【问题标题】:Updateable Data Grid using Linq to SQL in WinForms在 WinForms 中使用 Linq to SQL 的可更新数据网格
【发布时间】:2010-10-18 17:00:11
【问题描述】:

我正在使用 Linq 填充数据网格——标准类型的东西(下面的代码)。但是由于某种原因,我的 ultraDataGrid 陷入了某种只读模式。我已经检查了我能想到的所有网格属性。这是绑定到 Linq 数据源的结果吗?有人有使用 Linq 的可更新网格的示例代码吗?

db = New DataContext
myData = New dataClass
dataUltraGrid.DataSource = From table _
       In db.profiles _
        Select table.field1, table.field2...

【问题讨论】:

    标签: vb.net linq datagrid


    【解决方案1】:

    您真的没有使用 LinqDataSource 控件...您正在绑定到 List db.profiles 您的数据网格仅通过绑定到该列表而对更新、删除或插入一无所知,我可以建议:

    <asp:GridView ID="GridView1" runat="server" DataSourceID="LinqDataSource1" 
                AutoGenerateColumns="False" DataKeyNames="FooID">
                <Columns>
                    <asp:BoundField DataField="FooID" HeaderText="FooID" InsertVisible="False" 
                        ReadOnly="True" SortExpression="FooID" />
                    <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                    <asp:BoundField DataField="Description" HeaderText="Description" 
                        SortExpression="Description" />
                </Columns>
            </asp:GridView>
            <asp:LinqDataSource ID="LinqDataSource1" runat="server" 
                ContextTypeName="YourDataContext" EnableDelete="True" 
                EnableInsert="True" EnableUpdate="True" TableName="Foos">
            </asp:LinqDataSource>
    

    【讨论】:

    • 这是一个 ASP 的例子。我正在做winforms。这种逻辑会是什么样子?
    • 啊……抱歉,好久没做win表格申请了。我快速浏览了一下,不幸的是没有像 asp.net 那样的 LinqDataSource 控件
    【解决方案2】:

    找到解决方案:使用 lambda 表达式过滤实体并直接绑定到实体。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-17
      • 2017-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多