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

[Solved] Display Data based on selected Combobox value

1 Answer 164 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Megan
Top achievements
Rank 1
Megan asked on 16 May 2008, 04:10 PM
I'm having trouble understanding just how to use the selected value of a Combobox to display the correct data in a grid.


I have worked through this example but still my code is missing something:

http://www.telerik.com/DEMOS/ASPNET/Prometheus/Controls/Examples/Integration/GridComboAjax/DefaultCS.aspx?product=grid


It only works if I define a default value in the SQLDataSource's wizard.

Any ideas?

Here is my code:

                <telerik:radcombobox id="cboTime" runat="server" skin="Vista" DataSourceID="SqlTime"  DataTextField="sTimeId" AutoPostBack="True">  
                    <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
                </telerik:radcombobox>    
 
 
    <telerik:RadGrid ID="grdGrid" runat="server" DataSourceID="Sqlgrid" GridLines="None" Skin="Vista" AllowSorting="True" AllowPaging="True">  
        <MasterTableView DataSourceID="Sqlgrid">  
            <RowIndicatorColumn Visible="False">  
                <HeaderStyle Width="20px" /> 
            </RowIndicatorColumn> 
            <ExpandCollapseColumn Resizable="False" Visible="False">  
                <HeaderStyle Width="20px" /> 
            </ExpandCollapseColumn> 
            <EditFormSettings> 
                <PopUpSettings ScrollBars="None" /> 
            </EditFormSettings> 
        </MasterTableView> 
        <ClientSettings> 
            <Selecting AllowRowSelect="True" /> 
        </ClientSettings> 
    </telerik:RadGrid> 
 
    <asp:SqlDataSource ID="Sqlgrid" runat="server" ConnectionString="<%$ ConnectionStrings:MyDbConnectionString %>" 
        SelectCommand="Get_TimeTest" SelectCommandType="StoredProcedure">  
        <SelectParameters> 
            <asp:ControlParameter ControlID="cboTime" Direction="InputOutput" 
                Name="sTimeId" PropertyName="SelectedValue" Type="String" /> 
        </SelectParameters> 
    </asp:SqlDataSource> 
 
    <asp:SqlDataSource id="SqlTime" runat="server" SelectCommand="SELECT [sTimeId] FROM [Times]"   
    ConnectionString="<%$ ConnectionStrings:MyDBConnectionString2 %>">  
    </asp:SqlDataSource>      
</asp:Content> 

1 Answer, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 19 May 2008, 11:48 AM
Hello Megan,

Indeed if you would like your grid to show data on initial load, you will need to set default value for the SqlDataSource select parameter which matches the value of the selected item in the dropdown list. This is demonstrated in the online demo you pointed, here is the actual SqlDataSource definition:

<asp:AccessDataSource ID="dllDataSource" runat="server" DataFile="~/App_Data/Nwind.mdb" 
SelectCommand="SELECT TOP 20 [ContactName], [SupplierID] FROM [Suppliers]"></asp:AccessDataSource> 
<asp:AccessDataSource ID="gridSource" DataFile="~/App_Data/Nwind.mdb" SelectCommand="SELECT ProductID, ProductName, QuantityPerUnit, UnitPrice, UnitsInStock, Discontinued FROM Products WHERE SupplierID = ?" 
runat="server">  
            <SelectParameters> 
<asp:ControlParameter Name="SupplierID" DefaultValue="1" PropertyName="SelectedValue" 
ControlID="NamesDDL" /> 
            </SelectParameters> 
</asp:AccessDataSource> 

Best regards,
Stephen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
Megan
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Share this question
or