views:

70

answers:

2

Hello,

I'm learning LINQ and have run into a problem. I created a simple query against the northwind db, and I'm shaping the fields that should be returned. The problem is After run , I can't modify any of the fields in my AspxGridView .

<dxwgv:ASPxGridView ID="ASPxGridView1" runat="server" 
    AutoGenerateColumns="False" KeyFieldName="CategoryID">
    <Columns>
        <dxwgv:GridViewCommandColumn VisibleIndex="0">
            <EditButton Visible="True">
            </EditButton>
            <NewButton Visible="True">
            </NewButton>
            <DeleteButton Visible="True">
            </DeleteButton>
        </dxwgv:GridViewCommandColumn>
        <dxwgv:GridViewDataTextColumn Caption="CategoryID" FieldName="CategoryID" 
            VisibleIndex="1">
        </dxwgv:GridViewDataTextColumn>
        <dxwgv:GridViewDataTextColumn Caption="CategoryName" FieldName="CategoryName" 
            VisibleIndex="2">
        </dxwgv:GridViewDataTextColumn>
        <dxwgv:GridViewDataTextColumn Caption="Description" FieldName="Description" 
            VisibleIndex="3">
        </dxwgv:GridViewDataTextColumn>
    </Columns>
</dxwgv:ASPxGridView>

C# syntax:

protected void Page_Load(object sender, EventArgs e)
{
    NorthwindDataContext db = new NorthwindDataContext();
    var r = db.Categories
        .Select(p=>new {p.CategoryID,p.CategoryName,p.Description});
    ASPxGridView1.DataSource = r;
    ASPxGridView1.DataBind();
}

You guys may say it's problem for var anonymous type .But i always need to use anonymous type.How to solve this problem

+3  A: 

Don't think it is possible.

Anonymous types are class types that consist of one or more public read-only properties.

Quoted from http://msdn.microsoft.com

sgmoore
i know that.But i want to know is there any solution to solve this problem.Suppose there are two table"Orders"and "OrdersDetail"of Northwind database.Now i need to select both tabil values than what to do .is list type declaration work on .Than how to .Plz send some syntax
shamim
If you don't want them to be readonly then you CAN NOT use ANONYMOUS TYPES, but instead you have to define your own classes.
sgmoore
A: 

This isn't possible.

Scott Guthrie covered it in part 9 of his LINQ to SQL series:

One feature that will not work with custom shapes/projections, though, is inline editing support. This is because we are doing a custom projection in our Selecting event, and so the LinqDataSource has no way to safely know how to update an underlying entity object. If we want to add editing support to the GridView with a custom shaped type, we'd want to either move to using an ObjectDataSource control (where we could supply a custom Update method method to handle the updates), or have the user navigate to a new page when performing updates - and display a DetailsView or FormView control that was bound to a Product entity for editing (and not try and do inline editing with the grid).

Zhaph - Ben Duguid
i dont want to use datasource.I want to fill grid back end on C#.Than what to do .your given url describe how to work gridview using DataSource.Will u plz help me to fill grid by using C#
shamim