在DataGrid中删除记录时弹出确认窗口

发表于:2007-06-30来源:作者:点击数: 标签:
首先用模板列: asp:TemplateColumn HeaderText="删除" HeaderStyle Width="80px"/HeaderStyle ItemTemplate asp:LinkButton id="LinkButton" runat="server" Width="50px" ForeColor="Red" CommandName="Delete"删除/asp:LinkButton /ItemTemplate /asp:Tem
 

首先用模板列:
<asp:TemplateColumn HeaderText="删除">
<HeaderStyle Width="80px"></HeaderStyle>
<ItemTemplate>
<asp:LinkButton id="LinkButton" runat="server" Width="50px" ForeColor="Red" CommandName="Delete">删除</asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
后台:
VB:
    Sub dgrd_ItemCreated( s As Object, e As DataGridItemEventArgs )
        Select Case e.Item.ItemType
               Case ListItemType.Item, ListItemType.AlternatingItem
                Dim links As LinkButton
                links = e.Item.FindControl("btnDelete") 
                links.Attributes.Add("onclick", "return confirm(@#你是否确定删除?@#);")
        End Select
    End Sub
C#:
private void dgrd_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
switch(e.Item.ItemType)
{
case ListItemType.Item:
case ListItemType.AlternatingItem:
case ListItemType.EditItem:
{

LinkButton btnDelete=(LinkButton)e.Item.FindControl("btnDelete");

btnDelete.Attributes.Add("onclick", "return confirm(@#你是否确定删除?@#);");
                       break;
         }
             }
}

原文转自:http://www.ltesting.net