Access Selected GridViewRow in GridView
Dec 13
GridViewRow selectedRow = (GridViewRow)(((Control)e.CommandSource).NamingContainer);
Dec 13
GridViewRow selectedRow = (GridViewRow)(((Control)e.CommandSource).NamingContainer);
Dec 13
ASP.NET Comments Off
The following syntax sets the rowindex equal to the specific row number:
int rowindex = ((GridViewRow)((Control)e.CommandSource).Parent.Parent).RowIndex;
Dec 12
ASP.NET Comments Off
For example – inserting value in the empty gridview:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Insert") {
TextBox txt =
(((Control)e.CommandSource).NamingContainer).FindControl("txtTest") as TextBox;
//do insert action
}
}
Another way to do this is by getting EmptyDataTemplate table and its controls:
if (e.CommandName == "Insert")
{
Table table = (Table)GridView1.Controls[0];
TextBox txtTest= (TextBox)table.Rows[0].FindControl("txtTest");
//do insert actions
}