Sample code to get the index value in the RowCommand event

  • 2020-12-18 01:48:23
  • OfStack

Gets the index value in the RowCommand event

1. Use e. CommandSource
 
protected void lpg_RowCommand(object sender, GridViewCommandEventArgs e) 

{ 

if (e.CommandName == "ItemCollect") 
{ 
GridViewRow gvr = (GridViewRow)(((LinkButton)(e.CommandSource)).NamingContainer); 
LinkButton lk = lpgKnowledgeExchange.Rows[gvr.RowIndex].FindControl("lbtnCollect") as LinkButton; 

} 

} 

2. If button in the template column is a direct click event

Using sender to take its parent can also be realized

Related articles: