c# - Get the value of the checked item inside the gridview -
i have gridview defined
<asp:gridview id="gv1" runat="server" autopostback="true" onselectedindexchanged="gv1_selectedindexchanged"> <columns> <asp:templatefield> <itemtemplate> <asp:checkbox id="chk1" runat="server" /> <asp:boundfield datafield="name" headertext="name" sortexpression="name" readonly="true" /> </itemtemplate> </asp:templatefield> </columns> </asp:gridview>
the code handled
protected void gv1_selectedindexchanged(object sender, eventargs e) { foreach(gridviewrow row in gv1.rows) { checkbox check1 = (checkbox)row.findcontrol("chk1"); if(check1 != null && check1.checked) { label1.text = row.cells[1].text; } } }
the desired column @ index 1
however, value not obtained.
label1.text = row.cells[1].value.tostring()
Comments
Post a Comment