2017-07-28 56 views
0

我使用的DevExpress的GridView和有此代碼從另一個控制的customcallback刪除選定gridview的行,ASPxGridView DeleteRow不刪除另一個控制回調

GridFrom.DeleteRow(INT .Parse(rowKey [2]));

檢索正確的visibleIndex但不從GridView中刪除該行。該數據綁定也沒有刷新GridView的數據,它需要刷新頁面,爲數據更新

protected void ASPxTreeList1_CustomCallback(object sender, DevExpress.Web.ASPxTreeList.TreeListCustomCallbackEventArgs e) 
    { 
     string[] rowKey = e.Argument.Split('|'); 

     string strConnectionString = ConfigurationManager.ConnectionStrings["dbname"].ConnectionString; 
     using (SqlConnection conn = new SqlConnection(strConnectionString)) 
     { 
      string query = "DELETE FROM Table WHERE [email protected]"; 

      using (SqlCommand cmd = new SqlCommand(query, conn)) 
      { 
       conn.Open(); 
       cmd.Parameters.AddWithValue("@id", rowKey[0]); 
       cmd.ExecuteNonQuery(); 
       conn.Close(); 
      } 

     } 
     GridFrom.DeleteRow(int.Parse(rowKey[2])); //rowKey[2] is the visibleIndex 
     GridFrom.DataBind(); 
    } 
} 
+0

嘗試刪除'GridFrom.DataBind();',因爲不是所有的數據源都支持刪除方法。你確定該文件已被刪除數據庫? – Dani

回答

0

它需要的頁面清爽的數據更新

你不」 t看到網格更改,因爲只有 ASPxTreeList在期間更新它自己的回調。

作爲一種可能的解決方案,禁用ASPxTreeList的回調或使用網格的CustomCallback(以類似方式)刪除網格行。

<dx:ASPxTreeList ID="ASPxTreeList1" runat="server" EnableCallbacks="false"> 
</dx:ASPxTreeList> 

查看The concept of callbacks - Why is it impossible to update external control data during a callback to another control學習指南。