2014-10-17 277 views
1

我的問題很簡單。我想獲取新插入的行值,並且想要相應地更新GridView和我的數據源。在DevExpress AspxGridView中添加綁定到數據源的新行/記錄

New Record

由於在圖像高光區域顯示,我要得到這個電子郵件等領域,在代碼隱藏文件。我正在使用WebForms/VB.NET

這是我的aspx代碼。

<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" EnableTheming="True" Theme="DevEx" 
     OnDataBinding="ASPxGridView1_DataBinding" 
     OnRowUpdating="ASPxGridView1_RowUpdating" 
     OnRowInserting="ASPxGridView1_RowInserting" 
     OnRowInserted="ASPxGridView1_RowInserted" 
     > 
     <Columns> 
      <dx:GridViewCommandColumn VisibleIndex="0"> 
       <EditButton Visible="True"/> 
       <NewButton Visible="True"/> 
       <DeleteButton Visible="True" /> 
      </dx:GridViewCommandColumn> 
      <dx:GridViewDataColumn FieldName="Email" VisibleIndex="2" Name="Email"> 
       <EditFormSettings Caption="Email" /> 
      </dx:GridViewDataColumn> 
      <dx:GridViewDataColumn FieldName="FirstName" VisibleIndex="3" Name="FirstName" /> 
      <dx:GridViewDataColumn FieldName="LastName" VisibleIndex="4" Name="LastName" /> 
      <dx:GridViewDataColumn FieldName="Password" VisibleIndex="5" Name="Password" /> 
      <dx:GridViewDataColumn FieldName="RetryCount" VisibleIndex="6" Name="RetryCount" /> 
      <dx:GridViewDataColumn FieldName="MaxRetryCount" VisibleIndex="7" Name="MaxRetryCount" /> 
     </Columns> 
     <SettingsPopup> 
      <EditForm Width="600" /> 
     </SettingsPopup> 
    </dx:ASPxGridView> 

這是我的代碼背後。

Protected Sub ASPxGridView1_RowInserting(sender As Object, e As DevExpress.Web.Data.ASPxDataInsertingEventArgs) 
    Dim gridView As ASPxGridView = CType(sender, ASPxGridView) 

    ' What to write here??? 
    e.NewValues("Email") 'doesn't give anything 
    e.NewValues("Email") = "SomeEmail" 'It is also not working 

End Sub 

此鏈接令人困惑:Inserting new Row

注意,我不使用DataTable

+0

那麼你怎麼提供數據源到電網。您應該能夠在RowInserting事件中獲取值。 – 2014-10-17 10:22:44

+0

使用實體框架。 – 2014-10-17 10:34:55

回答

0

因爲我懷疑你不會錯過實體的實體 AspxGridView的框架。您正在將EnitiyFramework 數據源分配給網格。可能你只是創建了一些List 數據源並分配它。

我建議你通過下面的KB和範例。它會讓你知道如何在使用與EntityDataSource/Entity Framework綁定的ASPxGridView時實現常見場景。

參考文獻:

How to implement common scenarios when using ASPxGridView bound with EntityDataSource/Entity Framework
How to utilize CRUD operations within ASPxGridView bound with LinqDataSource when using Anonymous Types
ASPxGridView bound to EntityFramework - How t update data in several tables

根據文件,你會得到挑釁從e.NewValues字典RowInserting事件值。

手冊CRUD操作:

1)插入: - 處理的ASPxGridView.RowInserting事件;
- 創建一個DataContext實例;
- 創建一個新的DataItem並從e.NewValues字典中填充它的屬性;
- 將新的DataItem添加到相應的表;
- 提交更改;
- 將eventArgs e.Cancel屬性設置爲「true」以取消插入操作;
- 調用ASPxGridView.CancelEdit方法關閉EditForm。

0

你可以試試這個:

  1. 關閉編輯表單
  2. 刷新數據的aspxgridview(這將刷新兩個 數據源的數據網格):

我把這在C#但概念是相同的:

protected void dxGvCatalog_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e) 
{  
    // Here your code to save 

    // Close edit form 
    dxGvCatalog.CancelEdit(); 
    // reload Grid 
    reloadAspxGridView(); 
} 

public void reloadAspxGridView() 
{ 
    dxGvCatalog.DataSource = Class.ConsultAll();  // Change this to your data source 
    dxGvCatalog.Enabled = true; 
    dxGvCatalog.Visible = true; 
    dxGvCatalog.DataBind(); 
} 
相關問題