gridview点击某行获取值的问题
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
try
{
this.TextBox5.Text = "4";
this.TextBox4.Text = this.GridView1.Rows[e.NewSelectedIndex].Cells[2].Text.ToString();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//鼠标移动到每项时颜色交替效果
e.Row.Attributes["onmouseover"] = "e=this.style.backgroundColor;this.style.backgroundColor='#cccccc'";
e.Row.Attributes["onmouseout"] = "this.style.backgroundColor=e";
//设置悬浮鼠标指针形状为"小手"
e.Row.Attributes["style"] = "Cursor:hand";
//鼠标点击某行即选中某行
e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.GridView1, "Select$" + e.Row.RowIndex);
}
为什么我点击gridview某一行,this.TextBox4.Text获取不到值
[解决办法]
GridView1.Rows[GridView1.SelectedIndex].Cells[0].Text;
[解决办法]