簡體   English   中英

GridView的asp.net訪問刪除按鈕

[英]asp.net access delete button of gridview

如何訪問RowDataBound事件上的gridview命令域刪除按鈕? 如何訪問griview中的單元格和控件

看到:

protected void YourGrid_RowDataBound(Object sender, GridViewRowEventArgs e)
{
    Control button = e.Row.FindControl("btnSubmit");
    if (button != null && checkBox is Button)
    {
        // do what you want
    }
}

RowDataBound事件中,您可以通過FindControl方法訪問行內部控件。

在上面的示例中,我假設您的控件是帶有btnSubmit標識符的Button控件。

編輯:在作者的問題后附加說明:

(ButtonType)e.Row.Cells[commandFieldIndex].Controls[controlIndex];

ButtonTypeCommandField - ButtonLinkButtonImageButton使用的按鈕類型。 默認情況下, CommandField使用LinkButtons ,但是可以通過CommandField的ButtonType屬性對其進行自定義。

請嘗試下面的代碼。 這用於添加刪除確認。 但是您可以將其用於任何您想要的東西。

if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[1].HasControls())
{
LinkButton lnkbtnDelete = ((LinkButton)e.Row.Cells[1].Controls[0]);
lnkbtnDelete.Attributes.Add("onclick", "return confirm('Do you want to Delete?');");
}
} 

高溫超導

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM