一旦记录成功插入数据库,我试图将网格模式从插入更改为显示。这是我到目前为止的代码。不幸的是,添加后,网格仍处于插入模式
protected void gridLoc_InsertCommand(object sender, GridCommandEventArgs e)
{
GridEditFormInsertItem insertItem = (GridEditFormInsertItem)e.Item;
TextBox txtLocName= insertItem.FindControl("txtLocName") as TextBox;
locBLL.InsertLoc(txtLocName.Text, false);
gridLoc.DataBind();
}
答案 0 :(得分:0)
请尝试以下方法:
// close the insert form
e.Canceled = true;
gridLoc.MasterTableView.IsItemInserted = false;
gridLoc.MasterTableView.Rebind();
但是不要忘记删除该行:gridLoc.DataBind();
您的代码的最终版本:
protected void gridLoc_InsertCommand(object sender, GridCommandEventArgs e)
{
GridEditFormInsertItem insertItem = (GridEditFormInsertItem)e.Item;
TextBox txtLocName= insertItem.FindControl("txtLocName") as TextBox;
locBLL.InsertLoc(txtLocName.Text, false);
// close the insert form
e.Canceled = true;
gridLoc.MasterTableView.IsItemInserted = false;
gridLoc.MasterTableView.Rebind();
}