What is e.RowIndex and e.EditIndex in Gridview?

 Posted by vishalneeraj-24503 on 11/25/2013 | Category: ASP.NET Interview questions | Views: 21439 | Points: 40
Answer:

Basically e.RowIndex is used in Row_Deleting Event as well as Row_Command Event to find control ID within Gridview
whereas
e.EditIndex is ONLY used in Row_Updating Event to find control ID within Gridview.

In short,we can say that e.RowIndex is used in ITEMTEMPLATE whereas e.EditIndex is used in EDITITEMTEMPLATE.

For Ex:-

Inside Row_Command or Row_Deleting Event we can write:-

protected void grid_project_details_RowDeleting(object sender,GridViewDeleteEventArgs e)

{
try
{
Label lbl_project_id = grid_project_details.Rows[e.RowIndex].FindControl("lbl_project_id") as Label;
}
catch(Exception ex)
{
throw ex;
}
}


Same code,we can write inside Row Command event as :-

protected void grid_project_details_RowCommand(object sender,GridViewCommandEventArgs e)

{
try
{
Label lbl_project_id = grid_project_details.Rows[e.RowIndex].FindControl("lbl_project_id") as Label;
}
catch(Exception ex)
{
throw ex;
}
}


Inside Row_Updating Event we can write:-

protected void grid_project_details_RowUpdating(object sender,GridViewUpdateEventArgs e)

{
try
{
Label lbl_project_id = grid_project_details.Rows[e.EditIndex].FindControl("lbl_project_id") as Label;
}
catch(Exception ex)
{
throw ex;
}
}


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response