Sivajihero Hero

Sivajihero Hero

  • 1.9k
  • 105
  • 23.4k

Increment values in gridview column

Dec 29 2015 3:50 AM
In my gridview which is in update mode, I need to increment a column value.
Ex: In my gridview have 5 rows and three columns. I need to increment the serial number column value by 1. Increment Gridview1.Rows[1].Cells[2] value by 1 up to 5th row. But when I execute the code it will result the output put of all the column same. This is my code.

 {
    int totalRows = GridView1.Rows.Count;
    for (int RowIndex = 0; RowIndex < totalRows; RowIndex++)
    {
        GridViewRow row = GridView1.Rows[RowIndex];
        TextBox txtslno = row.FindControl("txtslno") as TextBox;
        int number = int.Parse(TextBox5.Text);
        if (GridView1.Rows.Count > 1)
        {
            for (int i = 0; i < GridView1.Rows.Count - 1; i++)
            {
                txtslno.Text = (number + 1).ToString();
                number++;
            }
        }
    }
}

Answers (5)