怎么获取GridView当前行第一列的数据

2024-11-03 05:38:41
推荐回答(2个)
回答1:

protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
GridViewRow row = GridView1.Rows[e.NewSelectedIndex];
if (row.RowState == DataControlRowState.Selected)
{
this.Label3.Text = row.Cells[1].Text.ToString();
this.txt1.Text ="你好";
}
}
但txt1中都没有值,好象都没有触发这事件,为什么?
msdn中说,当单某一行的选择BUTTON后,触发GridView1_SelectedIndexChanging事件,因此,你可以在GridView中加入选择BUTTON,然后用
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
this.Response.Write(this.GridView1.Rows[e.NewSelectedIndex].Cells[4].Text);
}

回答2:

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string tmp = GridView1.Rows[e.RowIndex].Cells[0].ToString(); //列索引,从0开始,0即为第一列
}