views:

1207

answers:

2

I'm populating a datagrid using Linq--standard kind of stuff (code below). For some reason however my ultraDataGrid is stuck in some kind of read-only mode. I've checked all the grid properties I can think of. Is that a result of binding to a Linq data source? Anyone have example code of an updatable grid that uses Linq?

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

Your really not using a LinqDataSource control... your are binding to a List db.profiles your data grid doesn't know anything about updating or deleting or inserting by just being bound to that list, can I suggets this:

<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>
J.13.L
This is an example for ASP. I'm doing winforms. What would that logic look like?
Jeff
ahh... sorry haven't done a win forms application in a while. I gave it a quick look and unfortunately there is no LinqDataSource control as with asp.net
J.13.L
A: 

Found the solution: use lamda expressions to filter the entity and bind directly to the entity.

Jeff