I am using the below code to get the row index
protected void gvESAPending_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
lblMsg.Text = "";
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = gvESAPending.Rows[index]; // Here incorrect format error is coming
}
}
But the index value is coming as 0. What is wrong here?
Aspx Code
'> '>
You can add OnRowCreteEvent
ASPX:
<asp:gridview id="gvESAPending" onrowcreated="gvESAPending_RowCreated" ...
CS :
protected void gvESAPending_RowCreated(Object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton addButton = (LinkButton)e.Row.Cells[0].Controls[0];
addButton.CommandArgument = e.Row.RowIndex.ToString();
}
}
GridViewRow row = gvESAPending.Rows[index];
By doing this your actually accessing the row at index. So if index = 2 your actually returning the third row in your gridviewrow.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.