mercredi 25 mai 2016

how to get value input type checkbox in repeaterItems ASP.net?

i have button delete message from database but i cant get value from checked checkbox in repeateritem. how can i do that? this my 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 from mailbox where mailboxid='"+id+"'", con);
            try
            {
                con.Open();
                cmd.ExecuteNonQuery();
            }
            catch (Exception er)
            {

            }
            finally
            {
                con.Close();
            }

        }
    }

}

this my 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> 




Aucun commentaire:

Enregistrer un commentaire