c# - How to get the value of input type checkbox in RepeaterItems (ASP.NET)? -
i have button delete message database cant value checked checkbox in repeateritem. how can that? btndelete:
protected void btndelete_click(object sender, eventargs e) { foreach (repeateritem aitem in rptinbox.items) { htmlinputcheckbox chk = (htmlinputcheckbox)aitem.findcontrol("chkrow"); if (chk.checked == true) { string id = chk.value.tostring(); sqlconnection con = new sqlconnection(constr); sqlcommand cmd = new sqlcommand("delete mailbox mailboxid='"+id+"'", con); try { con.open(); cmd.executenonquery(); } catch (exception er) { } { con.close(); } } } }
this html:
<asp:repeater id="rptinbox" runat="server"> <itemtemplate> <tr> <td><input type="checkbox" id="chkrow" value='<%#eval("mailboxid")%>' runat="server"/></td> <td><%#eval("from") %></td> <td><a href="inboxdetail.aspx?mailboxid=<%#eval("mailboxid") %>"><%#eval("subject") %></a></td> <td><%#eval("date") %></td> </tr> </itemtemplate> </asp:repeater>
you can store value in hidden field:
<asp:repeater id="rptinbox" runat="server"> <itemtemplate> <tr> <td> <input type="checkbox" id="chkrow" runat="server"/> <input type="hidden" id="hiddenmailboxid" value='<%# eval("mailboxid") %>' runat="server"/> </td> <td> <%#eval("from") %> </td> ... </tr> </itemtemplate> </asp:repeater>
and retrieve in code-behind:
htmlinputhidden hiddenmailboxid = aitem.findcontrol("hiddenmailboxid") htmlinputhidden; string id = hiddenmailboxid.value;
Comments
Post a Comment