c# - Capture Checked Value From Data Grid -
i continue error of
object not set instance of object
what need change code can execute succesfully?
html
<td valign="top" style="text-align: left; width: 200px;"> <asp:gridview runat="server" id="datagridtest" autogeneratecolumns="false" gridlines="both" showfooter="true" > <columns> <asp:boundfield datafield="field1" headertext="1st set" /> <asp:boundfield datafield="field2" headertext="2nd set" /> <asp:templatefield> <itemtemplate> <asp:label runat="server" text='<%#eval("categoryid") %>' id="managerid" visible="false"></asp:label> </itemtemplate> <itemtemplate> <asp:checkbox id="checked" runat="server" autopostback="false" checked='<%# convert.toboolean(eval("checked")) %>' /> </itemtemplate> </asp:templatefield> </columns> </asp:gridview> <asp:button runat="server" id="btnchecked" cssclass="buttons" text="add" onclick="btnc_click" /> </td>
c#
protected void btnc_click(object sender, eventargs e) { try { foreach (gridviewrow row in datagridtest.rows) { string id = ((label)row.findcontrol("managerid")).text; if (row.rowtype == datacontrolrowtype.datarow) { checkbox chk = (checkbox)row.findcontrol("checked"); if (chk.checked) {} else {} } } } catch (exception exception) { throw exception; } }
in html setting gridviews id
id="datagridtest"
but in code behind use "dgrd".this may root problem.
Comments
Post a Comment