Binding DevExpress AspxGridView to TypedList

Posts   
 
    
Posts: 3
Joined: 23-Nov-2007
# Posted on: 23-Nov-2007 17:20:50   

Hi I am using DevExpress Aspx Gridview and it is bound with ObjectDataSource. The select method "GetAllEmployees" for the datasource is written in a class EmployeeBusinessClass In GetAllEmployees method, i am using DataAccessAdapter method **FetchTypedList(ITypedListLgp2,IPredicateExpression,Int32,ISortExpression,Boolean) ** The return type of the GetAllEmployees function is EmployeeTypedList.

The grid is bound successfully and all employees are loaded in the gridview. When i click on the Edit button against a row in gridview, employee's data (Employee Name) is loaded in a textbox, but that textbox remains disabled and i couldn't edit data in that textbox. I couldn't understand why textbox is disabled on editing a row.

If I use the simple sqlDataAdapter to fill DataSet and bind gridvew with DataSet's DataTable, then on Click edit button textbox will be enabled for editing. e.g SqlConnection conn = new SqlConnection(_connectionString); SqlDataAdapter da = new SqlDataAdapter(sqlCmd, conn); DataSet ds = new DataSet(); conn.Open(); da.Fill(ds,"Employees"); conn.Close(); return ds.Tables["Employees"];

But by using FetchTypedList method, it is not worked properly.

Aspx GridView <dxwgv:ASPxGridView ID="GridViewEmployees" ClientInstanceName="GridViewEmployees" runat="server" AutoGenerateColumns="False" Width="600px" KeyFieldName="EmployeeID" DataSourceID="EmployeeDataSource" >

    <Columns>
        <dxwgv:GridViewCommandColumn VisibleIndex="0" Width="150px" >
            <EditButton Visible="True" >
            </EditButton>
            <NewButton Visible="True"> 
            </NewButton>
            <DeleteButton Visible="True" >
            </DeleteButton>
        </dxwgv:GridViewCommandColumn>

        <dxwgv:GridViewDataTextColumn  SortOrder="Descending" FieldName="EmployeeID" VisibleIndex="1"  ReadOnly="True" >
            <EditFormSettings Visible="False" />
        </dxwgv:GridViewDataTextColumn>

        <dxwgv:GridViewDataMemoColumn FieldName="EmployeeName" VisibleIndex="2">
        </dxwgv:GridViewDataMemoColumn>
    </Columns>

<SettingsEditing Mode="Inline" />

</dxwgv:ASPxGridView>

<aspfrowning bjectDataSource ID="EmployeeDataSource" runat="server" DeleteMethod="DeleteAgentNote" InsertMethod="InsertEmployee" SelectMethod="GetAllEmployees" TypeName="EmployeeBusinessClass" UpdateMethod="UpdateEmployee"> <UpdateParameters> <aspstuck_out_tongue_winking_eye arameter Name="EmployeeName" Type="Int32" /> <aspstuck_out_tongue_winking_eye arameter Name="EmployeeID" Type="Int32" /> </UpdateParameters>

    <SelectParameters>
       <asp:P arameter Name="EmployeeID" Type="String" DefaultValue="150" />
    </SelectParameters>
    <InsertParameters>
        <asp:P arameter Name="EmployeeName" Type="String" />
    </InsertParameters>
</asp:o bjectDataSource>
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 24-Nov-2007 02:34:43   

Hi,

TypedLists are designed for one-way read-only purposes. That's why (I guess) you are unable to edit it. You can use EntityCollections for that. Is that possible in your scenario?

Regards,

David Elizondo | LLBLGen Support Team
Posts: 3
Joined: 23-Nov-2007
# Posted on: 24-Nov-2007 16:58:42   

Hi

It works by using FetchEntityCollection method. I couldn't understant why it fails with FetchTypedList or FetchDataTable? What are the differences among these fetching methods?

Regards

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 24-Nov-2007 19:55:08   

The difference is that FetchTypedList and FetchDataTable retrieves read-only typed DataTables, FetchEntityCollection retrieves a collection of Entities. simple_smile

Typed DataTables are read-only, coz you may mix a lot of table fields, aggregates, expressions, etc. in it. So sometimes is impossible to make an update when you have a lot of these expressions fields.

Entity classes (and EntityCollections) are the preferred way to work when you are looking for two-way scenarios (Inserts and Updates) and TypedLists/TypedViews are designed for one-way (you only want to Fetch) scenarios.

Hope helpful wink

David Elizondo | LLBLGen Support Team
Posts: 3
Joined: 23-Nov-2007
# Posted on: 24-Nov-2007 20:12:09   

Hi

Thanks for the important information. One thing i tested with FetchDataTable or FetchTypedList method and i wanted to share that with you.

Suppose you have a method that returns Data Table using FetchDataTable method. Now add the following code with that DataTable returned from FetchDataTable method.

    **  System.Data.DataTable dtNew = new System.Data.DataTable();
        foreach (System.Data.DataColumn dc in dtReturned.Columns )
            dtNew.Columns.Add(dc.ColumnName);
        foreach (System.Data.DataRow dr in dtReturned.Rows)
            dtNew.ImportRow(dr);
        return dtNew;**

**Note: **dtReturned - DataTable which is got from FetchDataTable method.

Now, if you bind DevExpress gridview with dtNew and click on the Edit button. Column values are loaded into input controls (e.g textboxes) and these input controls are enabled now for editing. But this method is not efficient because it requires looping.

Do you observe any thing from the above mentioned method?

Regards

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 25-Nov-2007 02:04:49   

That's indeed true.

You are creating a DataTable, not a Typed DataTable. Even if you can bind that, how could you get back the changes to DB? frowning

Yes, the above snippet is inefficient, but nobody do that. The recommended way to do things are:

A. If you need two-way OR/M then go on EntityCollections. B. If you just need one-way OR/M for fetching and presenting data then go on TypedViews, TypedLists, DynamicLists.

In LLBLGen, both A and B provide an easy databinding with a minimal (or zero) lines of additional code. wink

David Elizondo | LLBLGen Support Team