2011-03-23 51 views
0

我在页面上工作,让用户将excel文件导入到我们的数据库中。我希望允许用户在提交信息之前操作某些字段,以便从Excel文件加载DataSet并将其绑定到GridView。出于某种原因,rowUpdate我的NewValues集合是空的。使用DataSet源更新GridView

这里是我的GridView:

<cc1:WWGridView ID="gvImportDisplay" runat="server" CssClass="grid-view" AllowSorting="false" ShowHeader="true" 
    AutoGenerateColumns="true" 
    AutoGenerateEditButton="true" 
    OnRowEditing="gvImportDisplay_RowEditing" 
    OnRowCancelingEdit="gvImportDisplay_RowCancelingEdit" 
    OnRowUpdating="gvImportDisplay_RowUpdating" 
    > 
    <EmptyDataTemplate>0 results found. </EmptyDataTemplate> 
</cc1:WWGridView> 

这里是我的代码背后的更新:

protected void gvImportDisplay_RowUpdating(object sender, GridViewUpdateEventArgs e) 
{ 
    foreach (DictionaryEntry entry in e.NewValues) 
    { 
     string headerText = entry.Key.ToString(); 
     if (string.IsNullOrEmpty(headerText)) 
      continue; 
     string newValue = entry.Value.ToString(); 
     if (excelDataSet.Tables["ExcelInfo"].Rows[gvImportDisplay.EditIndex][headerText] == null) 
      continue; 
     excelDataSet.Tables["ExcelInfo"].Rows[gvImportDisplay.EditIndex][headerText] = newValue; 
    } 
    gvImportDisplay.EditIndex = -1; 
    RefreshGridView(); 
} 

“excelDataSet”是被保存在回发之间的会话页面的一个属性。

当我通过代码在foreach被完全跳过,因为e.NewValues.Count = 0

任何人都可以看到为什么NewValues将是空的?在更新之前是否需要重新绑定GridView?或者也许是因为我没有DataKey它不起作用?没有列可以用作DataKey,因为我不能保证任何特定的列是唯一的。

回答

0

e.NewValues仍不能正常工作,我猜是因为我没有DataKeys。

我能够通过手动定义列和执行FindControl来获取更新,以获取新值。因为我将不得不手动定义列来处理网格视图的另一个方面,所以我将继续这样做。