使用gridview存储过程更新表不会更新我的表

时间:2018-07-06 13:04:54

标签: sql asp.net gridview

因此,当我单击“ edit”(编辑),然后键入一个新值,然后单击“ update”(更新)时。该值返回到原来的状态,有人知道我的代码在哪里出错了吗。我的存储过程是很好,但是我怀疑我的代码中缺少某些内容..当我逐步执行代码时,它只是获取表中的值,然后将其发送给我的存储过程...这是代码

 protected void GridView1_OnRowEditing(object sender, GridViewEditEventArgs e)
        {

            GridView1.EditIndex = e.NewEditIndex;
            GridView1.DataBind();
        }



        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            // Assign Target property Value

            TextBox tb = (TextBox) GridView1.Rows[e.RowIndex].FindControl("TargetTextBox"); //finds the target column
            Target = int.Parse((tb.Text));
            int id = int.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());
            using (DataManager dmgr = new DataManager())
            {
                dmgr.Connect("PRODUCTION");

                dmgr.PackingShiftTargetUpdate(id, Target);

                dmgr.Disconnect();
            }

            GridView1.EditIndex = -1;
            GridView1.DataBind();
        }
    }
}

1 个答案:

答案 0 :(得分:0)

要检查的几件事。通过Web应用程序运行编辑时,请确认已在sql表中进行了更改。如果不是,则您的Web应用程序调用存储的proc的方式存在问题,如果是,并且Web应用程序仍在显示旧数据,则与您在页面加载或回发时初始化GridView1的方式有关。如果您不使用PostBackTrigger,则需要AsyncPostBackTrigger(使用AJAX)或C#!IsPostBack,并将Gridview1链接到它

private void Page_Load()
{
if (!IsPostBack)
    {
        // call GridView1 here         
    }
}

如果您也可以使用Page_Load()函数代码片段来编辑问题,那将很有帮助