日期:2014-05-17  浏览次数:20413 次

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.html
------解决方案--------------------
在绑定事件里写
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"
……