用Gridview自带的select选中某一条数据。
请问怎样将这条数据具体的值,填如页面上对于的textbox里去。比如Gridview里
学号 姓名 成绩
001 周杰伦 50
002 周杰 25选中了周杰伦这条数据,怎样将学号 姓名 和成绩分别填入对应的textbox去?代码应该写在哪个事件下?求具体代码?感激不尽!
请问怎样将这条数据具体的值,填如页面上对于的textbox里去。比如Gridview里
学号 姓名 成绩
001 周杰伦 50
002 周杰 25选中了周杰伦这条数据,怎样将学号 姓名 和成绩分别填入对应的textbox去?代码应该写在哪个事件下?求具体代码?感激不尽!
{
int index = GridView1.SelectedIndex;
string xm = GridView1.Rows[index].Cells[1].Text;
string cj = GridView1.Rows[index].Cells[1].Text; }
string cj = GridView1.Rows[index].Cells[2].Text;
protected void Gridview1_SelectedIndexChanged(object sender, EventArgs e)
{
txtId.Text = Gridview1SelectedRow.Cells[0].Text.ToString(); //获取学号
txtName.Text= Gridview1SelectedRow.Cells[1].Text.ToString(); //获取姓名
txtScore.Text= Gridview1SelectedRow.Cells[2].Text.ToString(); //获取成绩
}
protected void Gridview1_SelectedIndexChanged(object sender, EventArgs e)
{
txtId.Text = Gridview1.SelectedRow.Cells[0].Text.ToString(); //获取学号
txtName.Text= Gridview1.SelectedRow.Cells[1].Text.ToString(); //获取姓名
txtScore.Text= Gridview1.SelectedRow.Cells[2].Text.ToString(); //获取成绩
} 上面掉了三个.
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
string a = Convert.ToString(this.GridView1.Rows[0].Cells[1].Text);
this.TextBox1.Text = a;
}
具体行具体可以改改