通过复选框列表进行以下转发器控制:
<asp:Repeater ID="rptItemList" runat="server"> <HeaderTemplate> </HeaderTemplate> <ItemTemplate> <div> <asp:CheckBox ID="chkItem" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"ItemName").ToString() %>' /> <asp:HiddenField ID="hdItem" runat="server" Value='<%# DataBinder.Eval(Container.DataItem,"ItemId").ToString() %>' /> </div> </ItemTemplate> <FooterTemplate> <asp:LinkButton ID="lbtnDel" runat="server" Text="Delete" OnClick="lbtnDel_Click" OnClientClick="return confirm('Are you sure you want to delete selected items from this list?')"></asp:LinkButton> </FooterTemplate> </asp:Repeater>
并按照后面的代码来处理lbtnDel_Click事件:
protected void lbtnDel_Click(object sender,EventArgs e) { foreach (RepeaterItem ri in rptItemList.Items) { CheckBox chk = (CheckBox)ri.FindControl("chkItem"); HiddenField hd = (HiddenField)ri.FindControl("hdItem"); if (chk.Checked) { var tc = new ItemController(); tc.DeleteItem(Convert.ToInt32(hd.Value)); } } Response.Redirect(DotNetNuke.Common.Globals.NavigateURL()); }
当我选中一个复选框并单击“删除”时,代码会找到该复选框,但会将其读取为未选中状态,因此不会删除该项目.
有任何想法吗?