惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Forbes - Security
Forbes - Security
GbyAI
GbyAI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
SegmentFault 最新的问题
Y
Y Combinator Blog
Recorded Future
Recorded Future
博客园 - Franky
I
InfoQ
T
The Blog of Author Tim Ferriss
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
阮一峰的网络日志
阮一峰的网络日志
T
Tailwind CSS Blog
Cyberwarzone
Cyberwarzone
The Register - Security
The Register - Security
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
雷峰网
雷峰网
P
Palo Alto Networks Blog
G
GRAHAM CLULEY
Cloudbric
Cloudbric
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
MongoDB | Blog
MongoDB | Blog
F
Full Disclosure
Google DeepMind News
Google DeepMind News
Recent Commits to openclaw:main
Recent Commits to openclaw:main
C
Check Point Blog
爱范儿
爱范儿
The GitHub Blog
The GitHub Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
W
WeLiveSecurity
T
Threat Research - Cisco Blogs
U
Unit 42
N
Netflix TechBlog - Medium
The Cloudflare Blog
Spread Privacy
Spread Privacy
Microsoft Azure Blog
Microsoft Azure Blog
美团技术团队
T
Troy Hunt's Blog
Engineering at Meta
Engineering at Meta
H
Heimdal Security Blog
TaoSecurity Blog
TaoSecurity Blog
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tenable Blog
B
Blog
S
Securelist
H
Hacker News: Front Page
Google Online Security Blog
Google Online Security Blog
G
Google Developers Blog

博客园 - 磊

淘宝店铺开业送优惠券 报表统计查询 Word 发布测试 【原创】hibernate中delete的一点见解 关于23种设计模式的有趣见解[转] 用Visual C#调用Windows API函数 2.0新控件 Localize ASP.NET直接下载一个文件 - 磊 - 博客园 dFastlog.dll错误和数据库连接错误的解决办法 "Automation 服务器不能创建对象" 的解决方法 - 磊 "FSO"的禁用与启用 如何做最简单的url跳转 我的主页 更换SQL对象属主的方法 如何在WinXP中批量修改文件名? Nokia 中的暂停功能 利用Forms实现两种不同验证系统 Froms验证 改版网站真麻烦
DataGrid,GridView和DetailsView中添加删除确认提示
· 2006-03-21 · via 博客园 - 磊

本文主要写如何在dotnet的DataGrid(1.0),GridView(2.0)和DetailsView(2.0)中添加删除确认提示。

先说1.0的DataGrid,添加DataGrid的ItemDataBound事件并添加以下类似代码

<asp:TemplateColumn HeaderText="删除">
                                                
<ItemTemplate>
                                                    
<asp:ImageButton ID="delete" Runat="server" CommandName="DelInfo" ImageAlign="Middle" ImageUrl="Images/btn_del.gif"></asp:ImageButton>
                                                
</ItemTemplate>
  
</asp:TemplateColumn>

DataGrid_ItemDataBound

注意:"SName"确认中要添加确认数据的列名,此例中用的是ImageButton其它按钮与此类似。

再说2.0的GridView,添加GridView的RowDataBound事件并添加以下类似代码

<asp:CommandField ShowDeleteButton="True" />

 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    
{
        
if (e.Row.RowType == DataControlRowType.DataRow)
            e.Row.Cells[
10].Attributes.Add("onclick""javascript:return confirm('你确认要删除\"" + e.Row.Cells[1].Text + "\"吗?')");

    }


注意:Cells[10]为删除按钮所在的列,删除按钮要在一个单独的列中,可以转化为模板列。

最后说DetailsView,直接利用.Net控件的OnClientClick如下:

<asp:TemplateField ShowHeader="False">
                    
<ItemTemplate>
                        
<asp:LinkButton ID="LinkButton1" runat="server" OnClientClick=" javascript:return confirm('你确认要删除吗?')" CausesValidation="False" CommandName="Delete"
                            Text
="删除"></asp:LinkButton>
                    
</ItemTemplate>
                
</asp:TemplateField>


好啦,到此结束。