zoukankan
html css js c++ java
DataGrid利用imagebutton实现删除操作
删除操作如图所示:
实现步骤:
1.在datagrid中创建模板列
2.在模板列中加入imagebutton并为其指定
ImageUrl
和
CommandName
,代码如下:
aspx代码
<
asp:TemplateColumn
>
<
ItemTemplate
>
<
asp:ImageButton id
=
"
ImageButton1
"
runat
=
"
server
"
ImageUrl
=
"
../Pic/delete.gif
"
CommandName
=
"
Del
"
></
asp:ImageButton
>
</
ItemTemplate
>
</
asp:TemplateColumn
>
3.在datagrid的
ItemCommand
事件中添加如下代码
单击删除图标时触发
private
void
DG_userinfo_ItemCommand(
object
source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if
(e.CommandName
==
"
Del
"
)
{
string
uid
=
e.Item.Cells[
0
].Text.ToString();
string
[] values
=
{uid}
;
OperateXmlByDataSet.DeleteXmlRows(ViewState[
"
filename
"
].ToString(),
"
userid
"
,values);
BindDG();
}
if
(e.CommandName
==
"
UpDt
"
)
{
string
userid
=
e.Item.Cells[
0
].Text.ToString();
ViewState[
"
uid
"
]
=
userid;
this
.Txt_id.Text
=
userid;
this
.Txt_name.Text
=
e.Item.Cells[
1
].Text.ToString();
this
.Txt_pass.Text
=
e.Item.Cells[
2
].Text.ToString();
this
.Txt_mail.Text
=
e.Item.Cells[
3
].Text.ToString();
this
.Txt_site.Text
=
e.Item.Cells[
4
].Text.ToString();
this
.Txt_msn.Text
=
e.Item.Cells[
5
].Text.ToString();
this
.Panel1.Visible
=
true
;
}
}
4.在datagrid的
ItemCreated
事件中添加如下代码
.cs代码
private
void
DG_userinfo_ItemCreated(
object
sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
System.Web.UI.WebControls.ImageButton ib;
foreach
(DataGridItem item
in
this
.DG_userinfo.Items)
{
ib
=
(ImageButton)item.FindControl(
"
ImageButton1
"
);
ib.Attributes.Add(
"
onclick
"
,
"
return confirm('您确定要删除?');
"
);
}
}
作者:
青羽
查看全文
相关阅读:
hdu 1166 敌兵布阵
linux(debian)系统django配远程连接sqlserver数据库
[机器学习] Coursera ML笔记
UICollectionView使用方法补充(照片轮播墙)
word中公式的排版及标题列表
FZOJ2110: Star
Windows 下的 Makefile 编写
掌握VS2010调试 -- 入门指南
Visual Studio 2010初学者的调试指南:Mastering Debugging in Visual Studio 2010
AlphaGo:用机器学习技术古老的围棋游戏掌握AlphaGo: Mastering the ancient game of Go with Machine Learning
原文地址:https://www.cnblogs.com/tenghoo/p/525863.html
最新文章
Apache同时支持PHP和Python的配置方法
Apache VirtualHost配置
RouterOS DNS劫持 -- A记录
添加Mysql到Windows系统服务
RouterOS首次打开网页强制跳转
解决类似 /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found 的问题
ZooKeeper监控工具(六)
zabbix 监控 oracle 数据库
Download Percona Monitoring Plugins
apache kafka系列之jmx监控指标参数
热门文章
工控安全简单入门
ORA-12537: TNS:connection closed错误处理过程
Free Syslog Forwarder–免费的Syslog转发工具
日志易快速接入
几种常见的Windows日志转SYSLOG工具的使用方法
Genymotion加入模拟器时报“Unable to create virtual device,Server returned HTTP status code 0”
机器学习算法笔记1_2:分类和逻辑回归(Classification and Logistic regression)
POJ 3683 Priest John's Busiest Day(2-sat)
黑马程序猿——15,String,StringBuffer,基本数据类型包装对象
C语言编程程序的内存怎样布局
Copyright © 2011-2022 走看看