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

2 radGrid on one aspx page

3 Answers 99 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 10 Sep 2008, 06:53 PM
I have a page that when I first load the page, I want to show a grid that has student information on it.  When the user selects Teacher from the dropdown box, I want the student grid to disappear and the Teacher grid that has totally different information and headers to appear.

I also want to enable paging on this page. 
My problem is the "NeedDataSource" for both grids.  It doesnt work for the teacher.

3 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 11 Sep 2008, 05:47 AM
Hi Mike,

When changing the grid visibility please call Rebind().

Greetings,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Princy
Top achievements
Rank 2
answered on 11 Sep 2008, 06:52 AM
Hello Mike,

You can change the DataSource on the SelectedIndexChanged property of the DropDownList. Check out the following code.
aspx:
  <asp:DropDownList ID="DropDownList1" AutoPostBack="true" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
         <asp:ListItem Text="student">         
        </asp:ListItem> 
        <asp:ListItem Text="teacher">         
        </asp:ListItem>            
        </asp:DropDownList> 
      
        <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" > 
            <MasterTableView DataSourceID="SqlDataSource1">               
            </MasterTableView> 
        </telerik:RadGrid> 
      
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MyDataBaseConnectionString %>" 
            SelectCommand="SELECT * FROM [Projects]"></asp:SqlDataSource> 
       
       <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:MyDataBaseConnectionString %>" 
           SelectCommand="SELECT * FROM [Reservation]"></asp:SqlDataSource> 

cs:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) 
    { 
        if (DropDownList1.Text == "teacher") 
        { 
            RadGrid1.DataSourceID = "SqlDataSource2"
        } 
        else 
        { 
            RadGrid1.DataSourceID = "SqlDataSource1"
        }         
    } 

Princy.
0
Mike
Top achievements
Rank 1
answered on 11 Sep 2008, 12:59 PM
The Teacher and Student Grids have different columns.
They are both templated, not create on the fly.

Changing just the datasource wont work, will it?
Tags
Grid
Asked by
Mike
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Princy
Top achievements
Rank 2
Mike
Top achievements
Rank 1
Share this question
or