I have a program in which items details are displaying. When I press next button it will display next item. the code is working, but when I press next until the last item in the row, the program shows error. So how to stop it wen it reaches the last row.
protected void Button2_Click(object sender, EventArgs e)
{
int i = ViewState["cnt"] !=null ? (int)ViewState["cnt"] : 0;
i = i + 1;
TextBox1.Text = GridView1.Rows[i].Cells[1].Text;
TextBox2.Text = GridView1.Rows[i].Cells[2].Text;
TextBox3.Text = GridView1.Rows[i].Cells[31].Text;
TextBox4.Text = GridView1.Rows[i].Cells[5].Text;
ViewState["cnt"] = i;
}