Gridview始终显示上一个选定的行

时间:2014-04-26 08:42:52

标签: c# asp.net gridview user-controls posting

我在选择行后再更新gridview,然后点击编辑工作完美但有一件事令我烦恼,每当我访问gridview时它会显示ROW SELECTED和Colored。为什么?我想要新的gridview,没有先前所选数据的记录。

CODE:

 protected void Page_Load(object sender, EventArgs e)
    {
        if (Session.Count <= 0)
        {
            Response.Redirect("login.aspx");
        }

        lblMsgPopUp.Visible = false;
    }

protected void btnUpdatePopUp_Click(object sender, EventArgs e) 
    {
        try
        {
            int ComplainantTypeID = Convert.ToInt32(txtSelectedID.Text.Trim());
            ComplainantTypeBizz comBizz = new ComplainantTypeBizz(txtName.Text);
            ManageComplainantType mngComplainantType = new ManageComplainantType();

            bool Result = mngComplainantType.Update(comBizz, ComplainantTypeID);

            if (Result == true)
            {
                HiddenFieldSetMessage.Value = "Updated";
                HiddenFieldShowMessage.Value = "True";
                Clear(txtName);
            }
            else
            {
                HiddenFieldSetMessage.Value = "NotUpdated";
                HiddenFieldShowMessage.Value = "True";
            }
        }
        catch (Exception)
        {
            HiddenFieldSetMessage.Value = "NotUpdated";
            HiddenFieldShowMessage.Value = "True";
        }
    }

1 个答案:

答案 0 :(得分:0)

您必须在GridView.DataBind();事件中编辑数据后将数据绑定到gridview(RowUpdated),并在每次数据绑定后设置GridView.SelectedIndex = -1;以取消选择网格中的任何行

protected void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
    GridView1.DataBind();
    GridView1.SelectedIndex = -1;
}

希望这有帮助。