protected void gvAttDoc_RowDataBound(object sender, GridViewRowEventArgs e){//check viewstate ถ้า dt = 0 ไม่ต้องทำ —

if (e.Row.RowType == DataControlRowType.DataRow){int ii = e.Row.RowIndex + 1;e.Row.Cells[0].Text = ii.ToString();}



so to sum it up to do this properly the code needed for the .cs page is:

    protected void GridView1_RowDataBound(Object sender, GridViewRowEventArgs e)
        if (e.Row.RowType == DataControlRowType.DataRow)

And the code for the aspx page is inserted just after the <Columns>tag:
<asp:TemplateField HeaderText=”ITEM NO”>
   <asp:Label ID=”lblNumber” runat=”server”/>
<ItemStyle HorizontalAlign=”Left” />
<HeaderStyle BorderColor=”Black” BorderStyle=”Inset” BorderWidth=”1px” HorizontalAlign=”Left” />
            Label lblNumber = (Label)e.Row.FindControl(“lblNumber”);
            lblNumber.Text = (e.Row.RowIndex + 1).ToString();