2014-03-05 202 views
0

後radgrid控件改變模式,我試圖從插入改變網格模式顯示,一旦該記錄已經成功插入到數據庫中。這是迄今爲止的代碼。加入後遺憾的是,電網仍處於插入模式插入記錄

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

請嘗試以下方法:

// 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();  
}