This is a migrated thread and some comments may be shown as answers.

Hooking up multiple data sources / tables with a single grid

1 Answer 605 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 19 Nov 2014, 11:13 PM
Just started learning Telerik APIs.  Using C# / Linq.  Reading up on MasterTableView and trying to hook up a simple grid which lists row data from an Orders table, including one column that lists the Name (a GridDropDownColumn) from a Customers table. So far no name is being displayed.

Where do I set datasource for the Customers table - how do I hook this up?
Thanks.
====
CREATE TABLE Customers
  (
    ID int NOT NULL IDENTITY(1,1) PRIMARY KEY,
    Name varchar(128) NOT NULL
  )

CREATE TABLE Orders
  (
    ID int NOT NULL IDENTITY(1,1) PRIMARY KEY,
    Description varchar(32) NOT NULL,
    CustomerID int NOT NULL FOREIGN KEY REFERENCES Customers(ID)
  )


    <telerik:RadGrid runat="server" ID="RadGrid_Order" AutoGenerateColumns="false" AllowPaging="true"
        OnNeedDataSource="RadGrid_NeedDataSource" OnUpdateCommand="RadGrid_UpdateCommand"
        OnItemCreated="RadGrid_ItemCreated" OnDeleteCommand="RadGrid_DeleteCommand"
        OnInsertCommand="RadGrid_InsertCommand" OnItemDataBound="RadGrid_ItemDataBound">
        <MasterTableView DataKeyNames="ID" CommandItemDisplay="Top" InsertItemPageIndexAction="ShowItemOnCurrentPage" EditMode="InPlace">
            <Columns>
                <telerik:GridEditCommandColumn ButtonType="ImageButton" />
                <telerik:GridBoundColumn DataField="ID" HeaderText="ID" ReadOnly="true" ForceExtractValue="Always" ConvertEmptyStringToNull="true" />
                <telerik:GridBoundColumn DataField="Description" HeaderText="Description" />
                <telerik:GridDropDownColumn UniqueName="RadCombo_Customer" HeaderText="Name" DropDownControlType="RadComboBox"
                    DataField="CustomerID" ListDataMember="Customers" ListValueField="ID" ListTextField="Name" />

                <telerik:GridButtonColumn ConfirmDialogType="RadWindow" ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" />
            </Columns>
            <EditFormSettings>
                <EditColumn ButtonType="ImageButton" />
            </EditFormSettings>
        </MasterTableView>
    </telerik:RadGrid>

        protected void RadGrid_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {
           RadGrid_Order.DataSource = OrdersTable.DataSource();  // query returns SELECT * FROM Orders;
        }


1 Answer, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 24 Nov 2014, 09:38 AM
Hello Peter,

To achieve the desired functionality you need to join the described tables. On the following link you can find information about JOIN statement in sql:
http://www.w3schools.com/sql/sql_join.asp
Also on the following link you can find information about supported data source of the RadGrid control:
http://www.telerik.com/help/aspnet-ajax/grid-binding-to-datatable-or-dataset.html

I hope this helps.  

Regards,
Radoslav
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Peter
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Share this question
or