Wednesday, February 3, 2010

Find row index of gridview on RowCommand without CommandArgument

Gridview has a template field with item linkbutton delete with CommandName now when user click on linkbutton then find the rowindex on Rowcommand event of gridview using C#.net

protected void grdtest1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "DeleteRow")
{
LinkButton gv = (LinkButton)e.CommandSource;
GridViewRow gvr = (GridViewRow)gv.Parent.Parent;
int rownum = gvr.RowIndex;
}
}