Reputation: 221
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
'> '>
Upvotes: 2
Views: 12787
Reputation: 1082
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();
}
}
Upvotes: 1
Reputation: 2072
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.
Upvotes: 0