日期:2014-05-18 浏览次数:20422 次
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { ((Button)e.Row.FindControl("btn3")).CommandArgument = e.Row.RowIndex.ToString(); ((Button)e.Row.FindControl("btn2")).CommandArgument = e.Row.RowIndex.ToString(); ((Button)e.Row.FindControl("btn3")).CommandName = "btn3"; } }
------解决方案--------------------
文件名:default6.aspx
满意请结贴,有问题请继续提问,谢谢!
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default6.aspx.cs" Inherits="Default6" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>无标题页</title> </head> <body> <form id="form1" runat="server"> <div> <asp:GridView ID="GridView1" runat="server"> </asp:GridView> Price:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>Quantity:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>Sum:<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox></div> </form> <script type="text/javascript"> function $(sElmID){return document.getElementById(sElmID);} var isIe=window.navigator.appName.indexOf("Netscape") == -1?true:false; var oRows=$("<%=GridView1.ClientID %>").rows; function initRow_Click(){ for(var i=1;i<oRows.length;++i){ oRows[i].onclick=new Function("onRow_Click(this)"); } } function onRow_Click(oSrc){ for(var i=1;i<oRows.length;++i){ oRows[i].style.background=""; } oSrc.style.background="orange"; var oCells=oSrc.getElementsByTagName("td"); $("<%=TextBox1.ClientID %>").value=isIe?oCells[0].innerText:oCells[0].textContent; $("<%=TextBox2.ClientID %>").value=isIe?oCells[1].innerText:oCells[0].textContent; $("<%=TextBox3.ClientID %>").value=isIe?oCells[2].innerText:oCells[0].textContent; } initRow_Click(); </script> </body> </html>
------解决方案--------------------
html:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" AllowSorting="true" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lblid" runat="server" Text='<%#Eval("id").ToString()%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="checkbox1" runat="server" ToolTip='&