2010-04-15 79 views

回答

0

參見:

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方法訪問行內部控制。

在上面的例子中,我假定您控制的是Button控件,標識符爲btnSubmit

編輯:筆者的問題的其他解釋後:

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

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

+0

找誰CommandField中按鈕...不是用戶刪除按鈕 的 2010-04-15 11:07:10

0

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

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?');"); 
} 
} 

HTH