在datagrid中刪除記錄時顯示提示

首先用模板列:
<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;
         }
             }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章