datagrid点删除,弹出一个确认和取消的消息框
有个简单的方法:
在datagrid的删除按扭
datagrid的属性生成器-》列-》添加按扭列-》删除
在数据字段中加上:
<div id="de" onclick="JavaScript:return confirm('确定删除吗?')">删除</div>
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
如果按钮类型是LinkButton,则用ItemCreated事件:
protected void MyDataGrid_ItemCreated(object sender, DataGridItemEventArgs e)
{
LinkButton myDeleteButton;
switch(e.Item.ItemType)
{
case ListItemType.Item:
case ListItemType.AlternatingItem:
myDeleteButton = (LinkButton) e.Item.Cells[0].Controls[0];
myDeleteButton.Attributes.Add("onclick", @"return confirm('与此记录关联的所有记录均会被删除,你确认要删除吗?');");
break;
}
}
如果是PushButton,只需在代码区加上:
<script language="jscript">
function delete_confirm(e){
if (event.srcElement.type=="submit" && document.all(event.srcElement.name).value =="删除" )
event.returnValue =confirm("确认是否删除?");
}
document.onclick=delete_confirm;
</script>
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
在DataGrid里面,要有一个这样的东东
<asp:TemplateColumn HeaderText="删除">
<ItemTemplate>
<asp:LinkButton id="btnDel" runat="server" CausesValidation="false" CommandName="Delete">
<IMG alt="删除用户" src="pic/stoplogin.gif" align="absMiddle" border="0"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
然后绑定几个事件
DataGrid1.ItemCreated+=new DataGridItemEventHandler(this.DataGrid1_ItemCreated);
DataGrid1.DeleteCommand+=new DataGridCommandEventHandler(this.DataGrid1_DeleteCommand);
然后
/// <summary>
/// 删除操作
/// </summary>
private void dgList_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
你的删除操作!
}
/// <summary>
/// 删除操作确认
/// </summary>
private void grid_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
ListItemType lit = e.Item.ItemType;
if(lit == ListItemType.Item || lit == ListItemType.AlternatingItem)
{
LinkButton del = (LinkButton)e.Item.FindControl("btnDel");
if(del==null)
{
return;
}
del.Attributes.Add("onclick","return confirm('确定要删除该纪录吗??')");
}
}
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
第一步:在DATAGRID中添加一个按钮列。
第二步:完成对DATAGRID的绑定后,为删除按钮添加一个提示信息。
for(int i=0;i<this.DataGrid1.Items.Count;i++)
{
//这里的this.DataGrid1.Items[i].Controls[6].Controls[0];请根据你的DATAGRID实际情况设定。
LinkButton lb = (LinkButton)this.DataGrid1.Items[i].Controls[6].Controls[0];
lb.Attributes.Add("onclick","javascript:if(!window.confirm('确定要删除这条记录吗?')) return false;");
}
第三步:为按钮添加处理函数
private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
//获得记录的编号
int recid = int.Parse(this.DataGrid1.DataKeys[e.Item.ItemIndex].ToString());
if(….)//这里的条件判断已被雷神删除。
DeleteOperate (recid); //调删除函数
else
Response.Write("<script language=javascript>window.alert('没有删除记录权限!');history.go(-1);</script>");
}
datagrid点删除,弹出一个确认和取消的消息框的更多相关文章
- 转 如何在调用WCF服务之前弹出一个确认对话框
自定义InteractiveChannelInitializer(InvocationConfirmationInteractiveChannelInitializer)定义如下.我们在BeginDi ...
- 确认框的使用。弹出一个确认框,Ajax提交一个请求,刷新页面。
视图: <td> @if (item.ReviewProject.DeclareState == DeclareOrReviewState.正在进行 && !item.Is ...
- 从点击Button到弹出一个MessageBox, 背后发生了什么
思考一个最简单的程序行为:我们的Dialog上有一个Button, 当用户用鼠标点击这个Button时, 我们弹出一个MessageBox. 这个看似简单的行为, 谁能说清楚它是如何运行起来的,背后究 ...
- 从点击Button到弹出一个MessageBox, 背后发生了什么(每个UI线程都有一个ThreadInfo结构, 里面包含4个队列和一些标志位)
思考一个最简单的程序行为:我们的Dialog上有一个Button, 当用户用鼠标点击这个Button时, 我们弹出一个MessageBox. 这个看似简单的行为, 谁能说清楚它是如何运行起来的,背 ...
- android在桌面弹出一个窗口
android在桌面弹出一个窗口 遇到了这种需求,要和iPhone一样的效果. 下面是简单实现功能,优化和美化部分,有时间慢慢搞. 方法应该有不少吧,我用的是弹出一个activity,将这个activ ...
- ASP.NET查询页面设置form的action属性只弹出一个页面,并且每次将页面设置到最前
原文:ASP.NET查询页面设置form的action属性只弹出一个页面,并且每次将页面设置到最前 背景 当数据量大.查询条件复杂,多样多的时候,我们可能需要单独做一个查询界面,当用户选择设置了相关的 ...
- 用MPLAB IDE编程时,软件总是弹出一个窗口提示: “the extended cpu mode configuration bit is enabled,but the program that was loaded was not built using extended cpu instructions. therefore,your code may not work properly
用MPLAB IDE编程时,软件总是弹出一个窗口提示:"the extended cpu mode configuration bit is enabled,but the program ...
- 点击文字弹出一个DIV层窗口代码
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <hea ...
- jQuery 学习笔记2 点击时弹出一个对话框
上次学习的是页面加载完成后弹出一个警告框,这里我们改为当用户点击后弹出一个警告框. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Trans ...
随机推荐
- 关于mybatis的@Param注解和参数
1,使用@Param注解 当以下面的方式进行写SQL语句时: @Select("select column from table where userid = #{userid} " ...
- WPF 如何控制右键菜单ContextMenu的弹出
在具体做一些项目的时候,有时候需要需要先左键点击某个节点,然后再右键点击节点的时候才弹出右键菜单,所以直接右键点击时需要禁用掉右键菜单,这里比如我们为Grid添加了ContextMenu,但是我们需要 ...
- Lodop打印二维码内容长度不同如何大小相同
利用Loodop打印控件打印二维码的时候,往往传入的数值是变量,有的只有一个数字,有的却一大堆数字和字母,根据内容长度不同,二维码大小也不同,这样如果批量打印二维码标签,传入的数据是不同的,会造成有的 ...
- std::shared_ptr 和普通指针的转换
相互转化见示例 struct test { int num; string name; }; test* pTest = new test(); std::shared_ptr<test> ...
- copy elison & RVO & NRVO
蓝色的博文 To summarize, RVO is a compiler optimization technique, while std::move is just an rvalue cast ...
- HNOI2018滚粗记
day 0 最近发现机房的人都有些焦虑(除了一些神犇)自己也被影响地紧张起来 唉,不知道是不是一种好的心态,紧张是必然的... 随便打了点板子(\(FFT,SA,LCT\)) 很棒一个都没考 day ...
- 20 Zabbix 利用Scripts栏目对Hosts远程执行命令
点击返回:自学Zabbix之路 点击返回:自学Zabbix4.0之路 点击返回:自学zabbix集锦 20 Zabbix 利用Scripts栏目对Hosts远程执行命令 在Monitoring板块中, ...
- SharePoint “File not found” 错误
Troubleshooting the SharePoint "File not found" Error Have you ever come across a "Fi ...
- 洛谷 P1984 [SDOI2008]烧水问题 解题报告
P1984 [SDOI2008]烧水问题 题目描述 把总质量为1kg的水分装在n个杯子里,每杯水的质量均为(1/n)kg,初始温度均为0℃.现需要把每一杯水都烧开.我们可以对任意一杯水进行加热.把一杯 ...
- UnicodeDecodeError: 'gbk' codec can't decode byte 0xae in position 9: illegal multibyte sequence
最近对爬虫有点着迷, 在用bs4模块时,遇到报错:UnicodeDecodeError: 'gbk' codec can't decode byte 0xae in position 9: illeg ...