2013-09-10 28 views
0

每次創建新項目時,都會在此代碼中發生錯誤。在線4檢測在radgrid中創建新記錄時是否存在項目

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
{ 
    if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
    { 
     GridEditableItem editedItem = e.Item as GridEditableItem; 
     string recordIDcreateDir = editedItem.GetDataKeyValue("TransazioneID").ToString(); 
     string subPath = "Allegati\\" + recordIDcreateDir; 
     bool isExists = System.IO.Directory.Exists(Server.MapPath(subPath)); 
     if (!isExists) 
      System.IO.Directory.CreateDirectory(Server.MapPath(subPath)); 
........ 

「參數超出範圍異常」顯然在創造新紀錄的「TransazioneID」價值現在還沒有,這就是爲什麼我得到的錯誤。 但是我怎樣才能使條件存在與if語句的記錄。 我試圖

if(editedItem.GetDataKeyValue("TransazioneID").ToString()== null); 
and.... 
if(editedItem.GetDataKeyValue("TransazioneID")!= null); and several others.... 

但不用其他任何成功。我怎樣才能捕捉該語句的某些內容以避免在創建項目時執行這些行?

回答

1

使用GridTableView.DataKeyNames

if (editedItem.OwnerTableView.DataKeyNames.Contains("TransazioneID")) { ... } 

從Telerik的docsGridEditableItem.GetDataKeyValue下指出:

從與相應項目的ItemIndex和的keyName所有者GridTableView獲取DataKeyValues。 keyName應該是DataKeyNames數組中指定的其中一個

+0

謝謝。它工作正常。 – FeliceM

相關問題