ASP.NET使用gridview获取当前行的索引值

2019-05-23 03:52:08丽君

protected void gvInfo_RowCreated(object sender, GridViewRowEventArgs e) 
{ 
if (e.Row.RowType == DataControlRowType.DataRow) 
{ 
LinkButton lk1 = (LinkButton)e.Row.FindControl("lkbtn");//LinkButton的ID 
lk1.CommandArgument = e.Row.RowIndex.ToString(); 
} 
} 
protected void gvInfo_RowCommand(object sender, GridViewCommandEventArgs e) 
{ 
if (e.CommandName == "ADD")//我LinkButton的CommandName 
{ 
int index = Convert.ToInt32(e.CommandArgument); 
string aa = gvInfo.Rows[index].Cells[1].Text.ToString();//获取当前行列号为一的值,列号从0开始 
} 
} 

以上所述就是本文的全部内容了,希望大家能够喜欢。