当前位置: 代码迷 >> ASP.NET >> asp.net datagrid 中删除提示 该如何写?
  详细解决方案

asp.net datagrid 中删除提示 该如何写?

热度:6230   发布时间:2013-02-25 00:00:00.0
asp.net datagrid 中删除提示 该怎么写???急!!!
C# code
                    <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中加什么呢??求高人指点,前后台代码。

------解决方案--------------------------------------------------------
百度
http://www.cnblogs.com/ocean010/archive/2008/12/01/1344847
------解决方案--------------------------------------------------------
在绑定事件里写
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('您真的要删除此行吗?');");
}
------解决方案--------------------------------------------------------
if (e.Row.RowType == DataControlRowType.DataRow)
{
ImageButton imgDel = (ImageButton)e.Row.FindControl("imgDel"); //判断是否为删除按钮
imgDel..Attributes.Add("onclick", "return confirm('确定删除该行数据吗吗?');
}
------解决方案--------------------------------------------------------
探讨
C# code

<asp:DataGrid ID="dg2" runat="server" AutoGenerateColumns="False"
DataKeyField="sid" HorizontalAlign="Center" Width="600px"
……
  相关解决方案