asp.net datagrid 中删除提示 该怎么写???急!!!

tracy1901 2012-05-14 11:31:13
                    <asp:DataGrid ID="dg2" runat="server" AutoGenerateColumns="False"  
DataKeyField="sid" HorizontalAlign="Center" Width="600px"
AllowPaging="True" AllowSorting="True" OnPageIndexChanged="dg2_PageIndexChanged"
OnCancelCommand="dg2_CancelCommand" OnDeleteCommand="dg2_DeleteCommand" OnEditCommand="dg2_EditCommand"
OnUpdateCommand="dg2_UpdateCommand" OnItemCommand="dg2_ItemCommand"
BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px"
CellPadding="4" ForeColor="Black" GridLines="Horizontal"
style="font-family: 微软雅黑; font-size: small; text-align: center;">
<FooterStyle BackColor="#CCCC99" ForeColor="Black" />
<HeaderStyle HorizontalAlign="center" BackColor="#333333" ForeColor="white"
Font-Bold="True" />
<PagerStyle HorizontalAlign="Right" Font-Size="small"
BackColor="White" ForeColor="Black"/>
<Columns>
<asp:BoundColumn HeaderText="2级目录名称" DataField="sname"></asp:BoundColumn>
<asp:EditCommandColumn EditText="编辑" CancelText="取消" UpdateText="更新" HeaderText="功能" ItemStyle-HorizontalAlign="center" CausesValidation="false">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:EditCommandColumn>
<asp:ButtonColumn Text="删除" HeaderText="功能" CommandName="del" CausesValidation="false" ItemStyle-HorizontalAlign="center" >
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:ButtonColumn>
</Columns>
</asp:DataGrid>


我想在删除时有个一个删除提示,网上搜的只有CS中的代码,我要在ASPX中加什么呢??求高人指点,前后台代码。
...全文
196 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
tracy1901 2012-05-15
  • 打赏
  • 举报
回复
这个函数名称及参数要怎么写呢?在aspx中datagrid里要加的是什么呢??
[Quote=引用 5 楼 的回复:]
在绑定事件里写
if(e.Item.ItemType == ListItemType.EditItem || e.Item.ItemType == ListItemType.AlternatingItem)
{
Button x = e.Item.Cells[2].Controls[0] as Button;
x..Attributes.Add("onclick", "return con……
[/Quote]
jdc71264 2012-05-15
  • 打赏
  • 举报
回复
[Quote=引用楼主 的回复:]
C# code

<asp:DataGrid ID="dg2" runat="server" AutoGenerateColumns="False"
DataKeyField="sid" HorizontalAlign="Center" Width="600px"
……
[/Quote]
给你推荐一个强大的办法,将Text的值不要直接写成删除,写成Text="<span style="color:blue" onclick="return confirm('你确定要删除该记录吗?')">删除</span>"
这个绝对强大
zhangdaowu5 2012-05-15
  • 打赏
  • 举报
回复
if (e.Row.RowType == DataControlRowType.DataRow)
{
ImageButton imgDel = (ImageButton)e.Row.FindControl("imgDel"); //判断是否为删除按钮
imgDel..Attributes.Add("onclick", "return confirm('确定删除该行数据吗吗?');
}
孟子E章 2012-05-15
  • 打赏
  • 举报
回复
在绑定事件里写
if(e.Item.ItemType == ListItemType.EditItem || e.Item.ItemType == ListItemType.AlternatingItem)
{
Button x = e.Item.Cells[2].Controls[0] as Button;
x..Attributes.Add("onclick", "return confirm('您真的要删除此行吗?');");
}
myhope88 2012-05-15
  • 打赏
  • 举报
回复
用js的confirm就行啦,写在cs或aspx中都行
myhope88 2012-05-15
  • 打赏
  • 举报
回复
用js的confirm就行了,不管在cs或者aspx页面中都可以写
何年 2012-05-15
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 的回复:]
引用楼主 的回复:
C# code

<asp:DataGrid ID="dg2" runat="server" AutoGenerateColumns="False"
DataKeyField="sid" HorizontalAlign="Center" Width="600px"
……

给你推荐一个强大的办法,将Text的值不要直接写成删除,写成Text="&lt;sp……
[/Quote]

看着的确很强大、、不过不熟悉的人容易看晕。。。
study_hard_01 2012-05-15
  • 打赏
  • 举报
回复
在RowDataBound事件中添加下面代码就可以了啊,我刚刚试过

if (e.Row.RowType == DataControlRowType.DataRow)
{
((LinkButton)(e.Row.Cells[5].Controls[0])).Attributes.Add("onclick", "return confirm('确定要删除吗?')");
}//cell[5]指的是你的删除按钮在第几列,比如我这个就是在第6列(0,1,2,3,4,5,6,)
shnaying1945 2012-05-15
  • 打赏
  • 举报
回复
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="删除" onclientclick="return confirm('确认删除?')"/>
nfclass 2012-05-14
  • 打赏
  • 举报
回复
确认提示吗? Js就可以了

62,025

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧