[英]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];
ButtonType
是CommandField
- Button
, LinkButton
或ImageButton
使用的按鈕類型。 默認情況下, 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.