【问题标题】:GridView will not update underlying data sourceGridView 不会更新底层数据源
【发布时间】:2008-09-09 19:02:14
【问题描述】:

所以我整天都在研究这个问题。我有一个指向我的模型的 LinqDataSource 和一个使用它的 GridView。当我尝试对 GridView 进行更新时,它不会更新基础数据源。我认为这可能与 LinqDataSource 有关,所以我添加了一个 SqlDataSource 并且发生了同样的事情。 aspx如下(代码隐藏页面为空):

  <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
      ConnectionString="Data Source=devsql32;Initial Catalog=Steam;Persist Security Info=True;" 
      ProviderName="System.Data.SqlClient" 
      SelectCommand="SELECT [LangID], [Code], [Name] FROM [Languages]" UpdateCommand="UPDATE [Languages] SET [Code]=@Code WHERE [LangID]=@LangId">
  </asp:SqlDataSource>
  <asp:GridView ID="_languageGridView" runat="server" AllowPaging="True" 
      AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="LangId" 
      DataSourceID="SqlDataSource1">
      <Columns>
          <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
          <asp:BoundField DataField="LangId" HeaderText="Id" ReadOnly="True" />
          <asp:BoundField DataField="Code" HeaderText="Code" />
          <asp:BoundField DataField="Name" HeaderText="Name" />
      </Columns>
  </asp:GridView>
  <asp:LinqDataSource ID="_languageDataSource" ContextTypeName="GeneseeSurvey.SteamDatabaseDataContext" runat="server" TableName="Languages" EnableInsert="True" EnableUpdate="true" EnableDelete="true">
 </asp:LinqDataSource>

我到底想念什么?这个问题快把我逼疯了。

【问题讨论】:

    标签: asp.net linq-to-sql data-binding


    【解决方案1】:

    【讨论】:

      【解决方案2】:

      事实证明,我们在 aspx 文件的母版页的 Page_Load 中有一个 DataBind() 调用,这可能导致 GridView 的状态在每次页面加载时都被抛出。

      请注意 - LINQ 查询的更新参数不是必需的,除非您想为它们设置一些非空默认值。

      【讨论】:

        【解决方案3】:

        由于我根本没有使用过 ASP,所以这完全是在黑暗中拍摄。

        我一直在学习 XAML 和 WPF,这似乎与您在上面发布的内容非常相似,并且我知道对于某些 UI 控件,您需要将绑定模式指定为双向以获取更新两个方向。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2011-07-07
          • 2019-12-01
          • 1970-01-01
          • 1970-01-01
          • 2023-04-07
          • 1970-01-01
          • 2010-11-29
          相关资源
          最近更新 更多