-1
我有按鈕從數據庫中刪除消息,但我無法從repeateritem中的複選框中獲取值。我怎樣才能做到這一點? 這是我btndelete:如何獲取RepeaterItems(ASP.NET)中的輸入類型複選框的值?
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();
}
}
}
}
這是我的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>