I am a new ASP.NET developer and I am trying to change the value of the first cell in each row in the GridVie by giving it a number starting from 1. It means that I want to add order to the list of things that will be displayed in the GridView.
I am using GridView RowDataBound method but now I don’t know to set the limit of the for loop in it. Could anyone help me with this?
My code-behind:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow) {
for(int i=1, i<; i++)
e.Row.Cells[0].Text = i;
}
}
If your requirement is “change the value of the first cell in each row”, it would be more like: