Hi,
i have a buttonfield in my gridview and want to access it from the rowdatabound event. Since it is not having ID , how can i refer or FindControl it in the event.
In Code behind :
protected void GridView_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Button btnSave = (Button) childGrid.Controls[0] ; // how to find buttonfield control here..
}
}
please suggest..!!
My advice is that you use a templatefield with a button inside. This will ale you to use e.Row.FindControl() to find the button by id.
i have done that using asp button control in template field. But trying to figure it out that is it possible with buttonfield control .
//for loop for row & column in gridview
Button sav=(Button)GridView1.Rows[i].Cells[j].FindControl("Button1");
But it would be better to use template field
Try like this: Button btnSave = (Button) e.Row.Cell[1].Controls[0];
You might need to play around with the indexes depending on your exact markup.
沒有留言:
張貼留言