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

Multiple tables in one radgrid

1 Answer 126 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tov
Top achievements
Rank 1
Tov asked on 03 Nov 2008, 12:08 AM
Hi everyone,

I am doing some practicals with radgrid. I'm just wondering if there is a way to display different datasources within one radgrid...

For example, I have three tables: products, customers, and order status.
in order to allow administration staff to modify the entries of those tables, I want them to choose one table from the dropdown list (or combobox). Thus, is there any solution available to display coorsponsdent table in the radgrid, like, "products" value has been selected in dropdown list, will the product table appear in the grid?

Ciao,
Tov

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 03 Nov 2008, 04:01 AM
Hi Tov,

You can achieve this by setting the DataSourceID of the Grid to the selected item in the DropDownList in its SelectIndexChanged event.


ASPX:
 <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" Width="109px" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
          <asp:ListItem Text="SqlDataSource1" ></asp:ListItem> 
          <asp:ListItem  Text="SqlDataSource2" ></asp:ListItem> 
        </asp:DropDownList> 
 
 
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthWindConnectionString1 %>" 
            SelectCommand="SELECT [ProductID], [ProductName], [SupplierID], [CategoryID] FROM [Products]"
        </asp:SqlDataSource> 
        <br /> 
        &nbsp;<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:NorthWindConnectionString2 %>" 
            SelectCommand="SELECT [OrderID], [CustomerID], [EmployeeID] FROM [Orders]"></asp:SqlDataSource> 

<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" GridLines="None" AllowPaging="True" OnItemCommand="RadGrid1_ItemCommand" OnItemDataBound="RadGrid1_ItemDataBound" OnPreRender="RadGrid1_PreRender" PageSize="5"
   <MasterTableView DataSourceID="SqlDataSource1" AutoGenerateColumns="true" > 
 
   </MasterTableView> 
</telerik:RadGrid> 


CS:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) 
    { 
        RadGrid1.DataSource = DropDownList1.SelectedItem.Text; 
    } 


Thanks
Shinu
Tags
Grid
Asked by
Tov
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or