为Gridview的CommandField删除添加"是否确认删除?"
2009-08-01 16:51
393 查看
为Gridview的CommandField删除添加"是否确认删除?"
为Gridview的CommandField删除添加"是否确认删除?" 在网上的方法很多,,也可以用,,例如以下::
首先,在GridView的属性对框话框中点击“Columns”进入它的“字段”设计器。接着在“字段”设计器中选择以前已加上的那个CommandField“删除”列,这时在它的属性列表下会看到一个“将此它段转换为 TemplateFied”的项,点击将它转换为TemplateFied列。
完后退出该字段设计器,切换到源码视图你会发现该列已由原来的:<asp:CommandField ShowDeleteButton="True" />
变为了:
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete" Text="删除"></asp:LinkButton>
</ItemTemplate>
最后在<asp:LinkButton>中加入:OnClientClick="return confirm('确认要删除吗?');"
这样点击删除时就会先在客户端弹出“确认要删除吗?”对话框,而原来在RowDeleting事件中写的代码完全不用改变。
在绑定方法里面写
for(int i;i<写你自己的GridView名称.Rows.Count;i++)
{
LinkButton lb=(LinkButton)写你自己的GridView名称.Rows[i].Cells[这里写你的索引值比方说在删除的那个按钮在第二列就写2].Controls[0你的GridView是第几个GridView控件就写几我先应该只有一个就写0吧];
lb.Attributes.Add("onclick","return confirm('真的要删除吗?')")
}
以下是我写的代码示例
/// <summary>
/// 绑定商品信息
/// </summary>
public void SpxxBD()
{
SelectStockService selservice = new SelectStockService();
GVspxx.DataSource = selservice.SelectGoodsInfo("");
GVspxx.DataBind();
for (int i = 0; i < GVspxx.Rows.Count; i++)
{
LinkButton linkbtn = (LinkButton)GVspxx.Rows[i].Cells[9].Controls[0];
linkbtn.Attributes.Add("onclick", "return confirm('真的要删除该货品吗?');");
}
}
转换成template
你在智能标记中选择 编辑列,你是否 有看到弹出窗口的右下角有一个"将此字段转换为TEMPLATEFIELD 的字样 ",你点那个链接后,原来的commandfield能实现的事情,它都可以帮你完成.. 然后你在template field中 只要加上 onClientClick="return confirm ('are you sure you want to delete this record?');" 即OK~...Hope it is usefull to you.....
相关文章推荐
- Gridview的CommandField删除添加"是否确认删除?"
- 为Gridview的CommandField删除添加"是否确认删除?"
- 为Gridview的CommandField删除添加 "是否确认删除?"
- 给DataGrid的删除按钮添加"删除确认"对话框
- GridView的第一列是ButtonField,字段名是"删除",想一点之后弹出确认框,否则返回.应该如何写?
- GridView的第一列是ButtonField,字段名是"删除",想一点之后弹出确认框,否则返回.应该如何写?
- GridView 结合ymPrompt脚本实现的确认是否删除操作
- 为GRIDVIEW“删除”列添加确认对话框
- fatal error C1010: 在查找预编译头时遇到意外的文件结尾。是否忘记了向源中添加“#include "stdafx.h
- fatal error C1010: 在查找预编译头时遇到意外的文件结尾。是否忘记了向源中添加“#include "stdafx.h
- windows"无法删除****,找不到指定文件,请确定指定的路径及文件名是否正确"的解决
- 为gridview的“删除”列添加确认对话框
- 为GridView添加删除确认的若干种方法
- 批处理应用:"添加/删除程序"修复
- 如何在GridView中添加CheckBox控件列,添加删除确认对话框
- 解决Installer重新安装补丁错误-"无法打开此修补程序包。请确认该修补程序包存在,并且您可以访问它,或者与应用程序供应商联系,以确认这是否是一个有效的 Windows Installer 修补程序包。"
- GridView中delete列添加删除确认对话框
- fatal error C1010: 在查找预编译头时遇到意外的文件结尾。是否忘记了向源中添加“#include "stdafx.h
- 如何在GridView中进行删除操作时弹出提示问是否确认删除?
- gridview添加删除确认对话框