ComboBox Select All on Grid Initial Load

4 posts, 0 answers
  1. Brett
    Brett avatar
    14 posts
    Member since:
    Feb 2014

    Posted 23 Mar 2014 Link to this post

    Currently I can load data into a Grid when a specific value is chosen from a ComboBox. When the page first loads it displays an empty grid though. I am trying to figure out how to have ALL values loaded onto the Grid when the user first visits the page. 

    This demo provides an example of what I am trying to do but I can't quite get it to work:
    http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridcomboajax/defaultcs.aspx?product=combobox



    Here is my current code:

    <%@ Page Title="Report" Language="C#" MasterPageFile="~/MasterPages/Site.Master" AutoEventWireup="true" CodeBehind="Report.aspx.cs" Inherits="Report" Theme="Default" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
     
     
        <table>
            <tr>
                <td><label>User: </Label></td>
                <td>
                    <telerik:RadComboBox ID="EmailRCB" runat="server" AutoPostBack="True" DataSourceID="dllDataSource"
                        DataTextField="email" DataValueField="email" Width="250px"
                        AppendDataBoundItems="true">
                        <Items>
                            <telerik:RadComboBoxItem Text="- Select User -" Value="0" Selected="true"></telerik:RadComboBoxItem>
                        </Items>
                    </telerik:RadComboBox>
                </td>
            </tr>
        </table><br />
     
     
        <!-- grid -->
            <telerik:RadGrid ID="OrdersGrid" AllowPaging="true" DataSourceID="gridSource" runat="server"
                GridLines="None" AllowSorting="true" ShowFooter="true" PageSize = "1000" Width="1500" >
                        <PagerStyle AlwaysVisible="true" ShowPagerText="true" Position="TopAndBottom" />
            <MasterTableView DataSourceID="gridSource" AllowMultiColumnSorting="false">
                <NestedViewTemplate>
                    <asp:Panel runat="server" ID="InnerContainer" Visible="true" ViewStateMode="Enabled">
                        <telerik:RadTabStrip runat="server" ID="tsMain" MultiPageID="mpMain" SelectedIndex="0">
                            <Tabs>
                                <telerik:RadTab runat="server" Text="Details" PageViewID="pvMain"  />
                            </Tabs>
                        </telerik:RadTabStrip>
                        <telerik:RadMultiPage runat="server" ID="mpMain" SelectedIndex="0" RenderSelectedPageOnly="false">
                            <telerik:RadPageView runat="server" ID="pvMain">
                                <asp:Label ID="lblNUM" Font-Bold="true" Font-Italic="true" Text='<%# Eval("NUMBER") %>' Visible="false" runat="server"></asp:Label>
                                <!-- inner/nested grid -->
                                <telerik:RadGrid runat="server" ID="grdOrders" DataSourceID="grdReportDataSource2" ShowFooter="false" AllowSorting="false" Width="700" EnableLinqExpressions="false">
                                    <MasterTableView ShowHeader="true" AutoGenerateColumns="true" AllowPaging="False">
                                    </MasterTableView>
                                </telerik:RadGrid>
                                <!-- datasource for inner/nested grid -->
                                <asp:SqlDataSource ID="grdReportDataSource2" runat="server"
                                ConnectionString="<%$ ConnectionStrings:intranetConnectionString %>"
                                SelectCommand="dbo.sp_AuditClientReportNested2" SelectCommandType="StoredProcedure" >
                                    <SelectParameters>
                                        <asp:ControlParameter ControlID="lblNUM" PropertyName="Text" Type="String" Name="NUM"></asp:ControlParameter>
                                    </SelectParameters>
                                </asp:SqlDataSource>
                            </telerik:RadPageView>
                        </telerik:RadMultiPage>
                    </asp:Panel>
                </NestedViewTemplate>
            </MasterTableView>
            <ClientSettings AllowDragToGroup="false">
            </ClientSettings>
            </telerik:RadGrid>
     
        </div>
     
     
        <!-- datasource for RadComboBox -->
        <asp:SqlDataSource ID="dllDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:intranetConnectionString %>"
            SelectCommand="SELECT DISTINCT EMAIL FROM Table1"></asp:SqlDataSource>
        <!-- datasource for outer/header grid -->
        <asp:SqlDataSource ID="gridSource" runat="server" ConnectionString="<%$ ConnectionStrings:intranetConnectionString %>"
            SelectCommand=" SELECT DISTINCT NUM AS 'Number', EMAIL AS 'Email', BATCHID AS 'Batch ID', NAME AS 'Name', COMPANY AS 'Company', RTRIM(FIRSTNAME) + ' ' + RTRIM(LASTNAME) AS 'Contact Name', DateAdded AS 'Date'
                            FROM Table1
                            WHERE EMAIL = @email
                            ORDER BY NUM">
            <SelectParameters>
                <asp:ControlParameter Name="email" PropertyName="SelectedValue" ControlID="EmailRCB">
                </asp:ControlParameter>
            </SelectParameters>
        </asp:SqlDataSource>
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" EnableAJAX="true" DefaultLoadingPanelID="RadAjaxLoadingPanel1">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="EmailRCB">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="OrdersGrid" LoadingPanelID="AjaxLoadingPanel1">
                        </telerik:AjaxUpdatedControl>
                        <telerik:AjaxUpdatedControl ControlID="EmailRCB"></telerik:AjaxUpdatedControl>
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
        </telerik:RadAjaxLoadingPanel>
     
     
     
     
    </asp:Content>

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 23 Mar 2014 in reply to Brett Link to this post

    Hi Brett,

    You can use the NeedDataSource event of the RadGrid to populate the RadGrid. You may try a similar approach as shown below:

    C#:
    bool isSelected = false;
    protected void EmailRCB_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        isSelected = true;
        OrdersGrid.Rebind();
    }
    protected void OrdersGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        if (isSelected)
      //Your query to populate the Grid
         OrdersGrid.DataSource = GetDataTable("SELECT * FROM Table1 where EMAIL= '" + EmailRCB.SelectedValue + "'");
        else
         OrdersGrid.DataSource = GetDataTable("SELECT * FROM Table1");
    }

    Thanks,
    Princy
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Brett
    Brett avatar
    14 posts
    Member since:
    Feb 2014

    Posted 24 Mar 2014 in reply to Princy Link to this post

    Thank your for your help. I tried using the code you provided but I am still unable to get it to work. It was saying that the GetDataTable does not exist in the current context so I generated a method stub to remove that error. Still no luck.
    Also, The demo that I was referencing did not have any code-behind so I am wondering if you know how I could get my project to work without the addition of code-behind.

    Thanks,
    Brett
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 25 Mar 2014 in reply to Brett Link to this post

    Hi Brett,

    Please have a look into the sample code snippet which works fine at my end.

    ASPX:
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" EnableAJAX="true" DefaultLoadingPanelID="RadAjaxLoadingPanel1">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="EmailRCB">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="OrdersGrid" LoadingPanelID="AjaxLoadingPanel1">
                    </telerik:AjaxUpdatedControl>
                    <telerik:AjaxUpdatedControl ControlID="EmailRCB"></telerik:AjaxUpdatedControl>
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Default">
    </telerik:RadAjaxLoadingPanel>
    <telerik:RadComboBox ID="EmailRCB" runat="server" AutoPostBack="True" DataSourceID="dllDataSource" DataTextField="ContactName" DataValueField="SupplierID" Width="250px" AppendDataBoundItems="true">
        <Items>
            <telerik:RadComboBoxItem Text="- Select User -" Value="0" Selected="true"></telerik:RadComboBoxItem>
        </Items>
    </telerik:RadComboBox>
    <telerik:RadGrid ID="OrdersGrid" AllowPaging="true" DataSourceID="gridSource" runat="server"
        GridLines="None" AllowSorting="true" ShowFooter="true" PageSize="1000" Width="1500">
        <PagerStyle AlwaysVisible="true" ShowPagerText="true" Position="TopAndBottom" />
        <MasterTableView DataSourceID="gridSource" AllowMultiColumnSorting="false">
            <NestedViewTemplate>
                <asp:Panel runat="server" ID="InnerContainer" Visible="true" ViewStateMode="Enabled">
                    <telerik:RadTabStrip runat="server" ID="tsMain" MultiPageID="mpMain" SelectedIndex="0">
                        <Tabs>
                            <telerik:RadTab runat="server" Text="Details" PageViewID="pvMain" />
                        </Tabs>
                    </telerik:RadTabStrip>
                    <telerik:RadMultiPage runat="server" ID="mpMain" SelectedIndex="0" RenderSelectedPageOnly="false">
                        <telerik:RadPageView runat="server" ID="pvMain">
                            <asp:Label ID="lblNUM" Font-Bold="true" Font-Italic="true" Text='<%# Eval("UnitPrice") %>' Visible="false" runat="server"></asp:Label>
                            <telerik:RadGrid runat="server" ID="grdOrders" DataSourceID="SqlDataSource1" ShowFooter="false" AllowSorting="false" Width="700" EnableLinqExpressions="false">
                                <MasterTableView ShowHeader="true" AutoGenerateColumns="true" AllowPaging="False">
                                </MasterTableView>
                            </telerik:RadGrid>
                        </telerik:RadPageView>
                    </telerik:RadMultiPage>
                </asp:Panel>
            </NestedViewTemplate>
        </MasterTableView>
        <ClientSettings AllowDragToGroup="false">
        </ClientSettings>
    </telerik:RadGrid>

    Thanks,
    Princy.
Back to Top