会员
周边
众包
新闻
博问
闪存
赞助商
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
higou
http://blog.higou.com
DataGrid 中使用 复选框(CheckBox) 删除纪录
实现效果如图,点击删除后删除所选纪录
在DataGrid中加入模板列加入Label用以表示该纪录编号(id)
然后再用模板列制作删除列 插入复选框 checkbox
删除按钮的代码如下:
public
void
btnDel_Click(
object
sender,EventArgs e)
{
//
要删除的id号
string
strId
=
""
;
foreach
(DataGridItem i
in
DataGrid1.Items)
{
CheckBox chk
=
(CheckBox)i.FindControl(
"
CheckBox1
"
);
if
(chk.Checked)
{
//
查找该CheckBox所对应纪录的id号,在Label2中
strId
+=
((Label)i.FindControl(
"
Label2
"
)).Text
+
"
,
"
;
}
}
if
(strId.Length
>
1
)
{
//
去掉最后的一个逗号
strId
=
strId.Substring(
0
,strId.Length
-
1
);
string
sql
=
"
delete from Dif_Info where [id] in (
"
+
strId
+
"
)
"
;
db.RunProc(sql);
Response.Write(
"
<script language=javascript>window.alert('操作成功');</script>
"
);
BindGrid();
}
}
在html页中加入按钮方法
<
asp:Button id
=
"
btnDel
"
onclick
=
"
btnDel_Click
"
runat
=
"
server
"
Text
=
"
删除
"
></
asp:Button
>
完成
posted on
2007-11-21 17:08
骇狗
阅读(
860
) 评论(
0
)
编辑
收藏
举报
刷新页面
返回顶部
导航
博客园
首页
新随笔
联系
订阅
管理
公告