GridView控件与CheckBox结合,实现…
来源:互联网 发布:天国王朝 演员 知乎 编辑:程序博客网 时间:2024/05/01 14:48
- <table style="border:solid 1px green"width="35%">
-
<tr> -
<tdstyle="background-color:Fuchsia;"> -
<strong> -
<span> -
GridView控件与checkbox控件结合 -
</span> -
</strong> -
</td> -
</tr> -
<tr> -
<td> -
<asp:GridViewID="GridView1" runat="server"BackColor="#DEBA84" BorderColor="#DEBA84"BorderStyle="None"BorderWidth="1px" CellPadding="3" CellSpacing="2"DataKeyNames="stuid"> -
<Columns> -
<asp:TemplateField > -
<HeaderTemplate> -
<asp:CheckBoxID="chAll" runat="server" Text="全选" OnCheckedChanged="chAll_CheckedChanged"/> -
</HeaderTemplate> -
-
<ItemTemplate> -
<asp:CheckBoxID="cbo" runat="server" /> -
</ItemTemplate> -
</asp:TemplateField> -
<asp:BoundFieldDataField="stuid" HeaderText="学生编号"/> -
<asp:BoundField DataField="stuname"HeaderText="姓名" /> -
<asp:BoundFieldDataField="stuadd" HeaderText="地址"/> -
<asp:BoundField DataField="stucity"HeaderText="城市" /> -
</Columns> -
<FooterStyleBackColor="#F7DFB5" ForeColor="#8C4510"/> -
<RowStyleBackColor="#FFF7E7" ForeColor="#8C4510"/> -
<SelectedRowStyleBackColor="#738A9C" Font-Bold="True"ForeColor="White" /> -
<PagerStyleForeColor="#8C4510" HorizontalAlign="Center"/> -
<HeaderStyleBackColor="#A55129" Font-Bold="True"ForeColor="White" /> -
</asp:GridView> -
</td> -
</tr> -
<tr> -
<td> -
<asp:Button ID="btndel"runat="server" Text="删除" OnClick="btndel_Click"/> -
<asp:Button ID="btncancel"runat="server" Text="取消选择"OnClick="btncancel_Click" /> -
</td> -
</tr> -
</table>
-
///<summary> -
/// 全选 -
///</summary> -
/// <paramname="sender"></param> -
/// <paramname="e"></param> -
protected voidchAll_CheckedChanged(object sender, EventArgse) -
{ -
foreach (GridViewRow gr in GridView1.Rows) -
{ -
CheckBoxch = (CheckBox)gr.FindControl("cbo"); -
//相互变幻 -
if(ch.Checked == true) -
{ -
ch.Checked = false; -
} -
else -
{ -
ch.Checked = true; -
} -
} -
} -
//取消选择 -
protected voidbtncancel_Click(object sender, EventArgs e) -
{ -
foreach (GridViewRow gr in GridView1.Rows) -
{ -
CheckBoxch = (CheckBox)gr.FindControl("cbo"); -
//取消选择 -
ch.Checked= false; -
} -
} -
//删除 -
protected voidbtndel_Click(object sender, EventArgs e) -
{ -
btndel.Attributes.Add("onclick","javascript:return confirm('确定删除吗?');"); -
//进行相关操作 -
SqlConnection con = newSqlConnection(ConfigurationManager.ConnectionStrings["connection"].ConnectionString); -
con.Open(); -
//for(inti=0;i<=GridView1.Rows.Count-1;i++) -
//{ -
foreach(GridViewRow gr in GridView1.Rows) -
{ -
CheckBoxch = (CheckBox)gr.FindControl("cbo"); -
if(ch.Checked == true) -
{ -
//定义删除行的字符串 -
string cmdtext = "delete fromstudent where - stuid="+GridView1.DataKeys[gr.RowIndex].Value.ToString();
-
//创建命令对象 -
SqlCommand cmd = newSqlCommand(cmdtext,con); -
//执行删除操作 -
cmd.ExecuteNonQuery(); -
} -
} -
//关闭数据库连接 -
con.Close(); -
//回绑数据 -
BindGridView(); -
Response.Write("<script>alert('删除成功。');</script>"); -
}
0 0
- GridView控件与CheckBox结合,实现…
- GridView控件与CheckBox结合,实现全选功能,同时实现删除选中的多行数据
- GridView控件与CheckBox结合,实现全选功能,同时实现删除选中的多行数据 .
- GridView与CheckBox结合实现多选删除
- GridView和CheckBox结合实现可选择删除
- GridView与CheckBox结合(VB.NET)
- GridView和CheckBox结合
- GridView和CheckBox结合
- GridView和CheckBox结合
- GridView和CheckBox结合
- GridView和CheckBox结合
- GridView行颜色交替及与checkbox 结合实现多选
- GridView控件实现批量删除功能(checkbox)
- jQuery与GridView控件结合示例
- GridView 与CheckBox 结合使用全选的问题
- 5.GridView和CheckBox结合:
- GridView和CheckBox结合使用
- gridview控件和checkbox
- Oracle数据库中游标,异常的简单应用
- 【转载】Repeater隔行变色,两个方…
- 获取ul下所有li
- GridView绑定ArraryList
- GridView 全选问题
- GridView控件与CheckBox结合,实现…
- asp.net GridView 删除时弹出确认…
- 页面使用Ajax控件,后台不能调用前…
- 页面音乐和视频播发器代码
- jQuery插件---获取URL参数
- 查询并删除重复记录的SQL语句
- JS禁用鼠标左键和自动关闭弹出窗口
- SQL server中如何只备份一张数据库表的数据
- java.lang.RuntimeException: Unable to start activity ComponentInfo解决方案