这是我的代码,但它不起作用
protected void Button2_Click(object sender, EventArgs e)
{
int i = 1;
if (GridView1.Rows.Count > 0)
{
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;
i++;
}
}
它没有下一个项目。
答案 0 :(得分:0)
使用此代码
protected void Button2_Click(object sender, EventArgs e)
{
int i = ViewState["cnt"]!=null? (int) ViewState["cnt"]:1;
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;
}