2012-02-01 344 views
0

我正在使用下面的C#從GridViews上的命令行中替換文本的「編輯,刪除和選擇」。C#CommandRow LinkBut​​ton添加Javascript

我想通過使用一個JavaScript'確認'對話框來提高這一點,使用戶在刪除行之前進行雙重檢查。我如何從LinkBut​​ton對象執行此操作?

private void commandIcons(GridViewRow row) 
{ 
    if (row.Cells[0].Controls.Count == 5) 
    { 
     // we have a edit delete select control row type, replace text labels with icons 
     LinkButton lbedit = (LinkButton)row.Cells[0].Controls[0]; 
     lbedit.Text = lbedit.Text == "Edit" ? "<img title=\"Edit\" class=\"icon\" src=\"Images/database_edit.png\" />" : lbedit.Text; 

     LinkButton lbdelete = (LinkButton)row.Cells[0].Controls[2]; 
     lbdelete.Text = lbdelete.Text == "Delete" ? "<img title=\"Delete\" class=\"icon\" src=\"Images/delete.png\" />" : lbdelete.Text; 

     LinkButton lbselect = (LinkButton)row.Cells[0].Controls[4]; 
     lbselect.Text = lbselect.Text == "Select" ? "<img title=\"Select\" class=\"icon\" src=\"Images/accept.png\" />" : lbselect.Text; 
    } 
} 

回答

1

您可以添加一個「OnClientClick」到鏈接按鈕詢問確認。之後使用「OnClick」執行C#函數。希望能幫助到你。

<asp:LinkButton ID="Deletebutton" runat="server" CausesValidation="False" OnClientClick='return confirm("Are you sure you want to remove this?");' OnClick="DeleteBrand"> 

+0

完美,OnClientClick這個正是財產我了! – deed02392 2012-02-01 10:58:13

+0

好聽,自己在所有的aspx頁面中使用它。很高興我能幫忙 – DerDee 2012-02-01 11:01:52