为什么我不能抓住Gridview行的值?

时间:2013-04-25 10:44:29

标签: c# asp.net-mvc gridview

这是我的代码。 问题:当点击om一行och on选择页面刷新,我没有得到lable17.text中的文本。

 protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{

    GridViewRow row = GridView1.SelectedRow;

    Label17.Text = row.Cells[2].Text.ToString() ;
}


protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        e.Row.Attributes.Add("onmouseover", "this.style.cursor='Pointer';this.style.backgroundColor='Yellow'");

    }
}

protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
    GridViewRow row = GridView1.Rows[e.NewSelectedIndex];
    Label17.Text = "you selected" + row.Cells[2].Text;
}

1 个答案:

答案 0 :(得分:0)

GridViewUpdatePanel吗?如果不是,当您单击按钮时,整个页面将回发。另外,如果您在Text事件中设置Label17 Page_Load,请确保您第一次只执行此操作,例如

public void Page_Load(object sender, EventArgs e)
{
    if(!Page.IsPostBack)
    {
        Label17.Text = "Default Text";
    }
}