猿问
回到首页
个人中心
反馈问题
注册登录
下载APP
首页
课程
实战
体系课
手记
专栏
慕课教程
asp.net mvc beta 中checkbox 删除问题???
beta中已经没有checkboxlist,不知怎样利用checkbox做一个批量删除,怎样通过foreach来遍历选中的项,然后传到controller中进行删除呢。谢谢
PIPIONE
浏览 325
回答 2
2回答
千巷猫影
其实实现很简单:详细代码如下前台主要代码: <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" Width="667px"> <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" /> <Columns> <asp:TemplateField> <HeaderTemplate> <asp:CheckBox ID="cbAll" runat="server" AutoPostBack="True" OnCheckedChanged="cbAll_CheckedChanged" /> </HeaderTemplate> <ItemTemplate> <asp:CheckBox ID="cbSelect" runat="server" /> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="userID" HeaderText="用户编号" /> </Columns> <RowStyle BackColor="#E3EAEB" /> <EditRowStyle BackColor="#7C6F57" /> <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" /> <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" /> <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" /> <AlternatingRowStyle BackColor="White" /> </asp:GridView> <br /> </div> <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Delete" />后台主要代码:实现全选的代码//全选 protected void cbAll_CheckedChanged(object sender, EventArgs e) { for (int i=0; i < GridView1.Rows.Count;i++ ) { if(((CheckBox)sender).Checked==true) { ((CheckBox)GridView1.Rows[i].Cells[0].FindControl("cbSelect")).Checked = true; } else { ((CheckBox)GridView1.Rows[i].Cells[0].FindControl("cbSelect")).Checked = false; } }选中checkbox删除的方法 //删除 protected void Button2_Click(object sender, EventArgs e) { for (int i = 0; i < GridView1.Rows.Count; i++) { if (((CheckBox)GridView1.Rows[i].Cells[0].FindControl("cbSelect")).Checked = true) { int id =Convert.ToInt32(GridView1.Rows[i].Cells[1].Text.ToString()); DelData(id);//调用删除数据的数据处理方法 } } BindData();//重新绑定数据的方法 }
0
0
0
打开App,查看更多内容
随时随地看视频
慕课网APP
相关分类
.NET
.net 中 字符串含有超链接,如何给超链接自动加上a标签?
1 回答
请问.net 中用jquery传值安全吗?
2 回答
继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续