Filter RadGrid using RadComboBox with Multi-CheckBoxes Selection

2 posts, 0 answers
  1. Ali
    Ali avatar
    24 posts
    Member since:
    Apr 2010

    Posted 12 Nov 2014 Link to this post

    Hi,
    I am trying to filter the RadGrid [Grd_Url] using a RadComboBox [Cmb_Lst_Sel] which is inside "CommandItemTemplate". The RadComboBox has CheckBoxes enable and user can select multiple checkboxes. The RadGrid needs to be selected based on the multiple selection [DataValueField="lst_id"]. How can I do that?

    ASPX:
    ----------------------------------------------------------------------

    <telerik:RadGrid ID="Grd_Url" runat="server" GridLines="None" AllowSorting="true" AllowPaging="true" PageSize="50"
        AllowFilteringByColumn="true" AutoGenerateColumns="False" AllowMultiRowSelection="true" AllowMultiRowEdit="true"
        AllowAutomaticInserts="True" AllowAutomaticUpdates="True" AllowAutomaticDeletes="True" 
        DataSourceID="Sql_Url" Width="100%">
        <SortingSettings SortToolTip=""/>
        <FilterItemStyle Width="100%"></FilterItemStyle>
        <GroupingSettings CaseSensitive="false"></GroupingSettings>
        <PagerStyle AlwaysVisible="true" Mode="NextPrevAndNumeric"/>
        <MasterTableView DataKeyNames="url_id" CommandItemDisplay="Top" EditMode="InPlace" InsertItemPageIndexAction="ShowItemOnCurrentPage"
            GroupLoadMode="Client" GroupsDefaultExpanded="true" TableLayout="Fixed" Width="100%">
            <GroupByExpressions>
                <telerik:GridGroupByExpression>
                    <SelectFields>
                        <telerik:GridGroupByField FieldName="lst_name"></telerik:GridGroupByField>
                        <telerik:GridGroupByField FieldName="lst_sort"></telerik:GridGroupByField>
                    </SelectFields>
                    <GroupByFields>
                        <telerik:GridGroupByField FieldName="lst_sort" SortOrder="Ascending"></telerik:GridGroupByField>
                        <telerik:GridGroupByField FieldName="lst_name" SortOrder="Ascending"></telerik:GridGroupByField>
                    </GroupByFields>
                </telerik:GridGroupByExpression>
            </GroupByExpressions>
            <CommandItemTemplate>
            <div id="Div_Tlb_Fixed">
                <telerik:RadToolBar ID="Tlb_Url" runat="server" EnableImageSprites="true"
                    OnButtonClick="CsTlbClick" OnClientButtonClicking="jsTlbUrl">
                    <Items>
                        <telerik:RadToolBarButton CommandName="Toggle" PostBack="false" ToolTip="Expand/Collapse Folders"
                            CssClass="Btn_ToggleN" HoveredCssClass="Btn_ToggleH"
                            CheckOnClick="true" AllowSelfUnCheck="true" Group="T">
                        </telerik:RadToolBarButton>

                        <telerik:RadToolBarButton CommandName="Clear" PostBack="false" ToolTip="Clear Website Selection"
                            CssClass="Btn_ClearN" HoveredCssClass="Btn_ClearH">
                        </telerik:RadToolBarButton>
                    </Items>
                </telerik:RadToolBar>
                <telerik:RadComboBox ID="Cmb_Lst_Sel" runat="server" DataTextField="lst_name" CheckBoxes="true"
                    DataValueField="lst_id" AutoPostBack="True" EnableCheckAllItemsCheckBox="true" 
                    DataSourceID="Sql_Lst" Width="20%">
                    <Items>
                        <telerik:RadComboBoxItem Text="All" Value="" Selected="true"></telerik:RadComboBoxItem>
                    </Items>
                </telerik:RadComboBox> 
            </div>
            </CommandItemTemplate>
            <Columns>
                <telerik:GridBoundColumn DataField="lst_id" HeaderText="Folder ID" SortExpression="lst_id" 
                    UniqueName="lst_id" Display="false">
                    <HeaderStyle HorizontalAlign="Left" Width="1%"/>
                    <ItemStyle HorizontalAlign="Left" Width="1%"/>
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="lst_name" HeaderText="Folder Name" SortExpression="lst_name" 
                    UniqueName="lst_name" Display="false">
                    <HeaderStyle HorizontalAlign="Left" Width="1%"/>
                    <ItemStyle HorizontalAlign="Left" Wrap="false" Width="1%"/>
                </telerik:GridBoundColumn>
                <telerik:GridTemplateColumn DataField="url_name" HeaderText="Website Name" SortExpression="url_name" 
                    UniqueName="url_name" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" 
                    ShowFilterIcon="false" FilterControlWidth="100%">
                    <HeaderStyle HorizontalAlign="Left" Width="25%"/>
                    <ItemStyle HorizontalAlign="Left" Width="25%"/>
                    <ItemTemplate>
                        <asp:HyperLink ID="Hyp_url_name" runat="server" Target="_blank" Font-Underline="false"
                            NavigateUrl='<%# Eval("url_address") %>'><%# Eval("url_name") %>
                        </asp:HyperLink>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadTextBox runat="server" ID="Gce_url_name" MaxLength="128" 
                            Text = '<%# Bind("url_name") %>' Width="100%">
                        </telerik:RadTextBox>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn DataField="url_address" HeaderText="Website Address" SortExpression="url_address" 
                    UniqueName="url_address" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" 
                    ShowFilterIcon="false" FilterControlWidth="100%">
                    <HeaderStyle HorizontalAlign="Left" Width="47%"/>
                    <ItemStyle HorizontalAlign="Left" Width="47%"/>
                    <ItemTemplate>
                        <asp:HyperLink ID="Hyp_url_address" runat="server" Target="_blank" Font-Underline="false"
                            NavigateUrl='<%# Eval("url_address") %>'><%# Eval("url_address")%>
                        </asp:HyperLink>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridEditCommandColumn UniqueName="Btn_Edit" ButtonType="ImageButton" EditText="Edit" HeaderText="Edit">
                    <HeaderStyle HorizontalAlign="Center" Width="7%"/>
                    <ItemStyle HorizontalAlign="Center" Width="7%"/>
                </telerik:GridEditCommandColumn>
                <telerik:GridButtonColumn CommandName="Delete" UniqueName="Btn_Delete" ButtonType="ImageButton" Text="Delete"
                    ConfirmDialogType="RadWindow" ConfirmTitle="Delete" ConfirmText="Delete the selected websites(s)? You cannot UNDO the operation.">
                    <HeaderStyle HorizontalAlign="Center" Width="4%"/>
                    <ItemStyle HorizontalAlign="Center" Width="4%"/>
                </telerik:GridButtonColumn>
            </Columns>
        </MasterTableView>
        <ClientSettings AllowRowsDragDrop="true" AllowColumnsReorder="false" AllowKeyboardNavigation="false"
                AllowGroupExpandCollapse="true" AllowDragToGroup="false">
            <Selecting AllowRowSelect="true" EnableDragToSelectRows="true"/>
            <Resizing AllowRowResize="true" AllowColumnResize="true" AllowResizeToFit="true" EnableRealTimeResize="true" 
                ResizeGridOnColumnResize="false" ShowRowIndicatorColumn="false" ClipCellContentOnResize="false"/>
            <Scrolling AllowScroll="false" SaveScrollPosition="true"/>
            <KeyboardNavigationSettings AllowSubmitOnEnter="true"/>
            <ClientEvents OnRowDblClick="jsRowDblClick" OnRowDropping="onRowDropping"/>
        </ClientSettings>
    </telerik:RadGrid>

    <asp:SqlDataSource ID="Sql_Url" runat="server" OnInserting="CsSqlInserting" OnSelecting="CsSqlSelecting"
    ConnectionString="<%$ ConnectionStrings:Con_Str %>" 
        DeleteCommand="DELETE FROM [t_Urls] WHERE [url_id] = @url_id" 
        InsertCommand="INSERT INTO [t_Urls] ([url_id], [usr_id], [lst_id], [url_isOpen], [url_name], [url_address], [url_sort]) 
                       VALUES (NEWID(), @usr_id, @lst_id, @url_isOpen, @url_name, @url_address, @url_sort)" 
        SelectCommand="SELECT b.[lst_id], b.[lst_name], b.[lst_sort], a.[url_id], a.[url_isOpen], a.[url_name], a.[url_address], a.[url_sort] 
                       FROM (SELECT * FROM [t_Urls] WHERE [usr_id] = @usr_id) a 
                       INNER JOIN 
                       (SELECT * FROM [t_Lists] WHERE [usr_id] = @usr_id AND [lst_type] IN ('a', @lst_type_filter)) b 
                       ON a.[lst_id] = b.[lst_id] 
                       ORDER BY b.[lst_sort] ASC, a.[url_sort] ASC, a.[url_date] DESC"
        UpdateCommand="UPDATE [t_Urls] SET [lst_id] = @lst_id, [url_isOpen] = @url_isOpen, [url_name] = @url_name, 
                       [url_address] = @url_address, [url_sort] = @url_sort WHERE [url_id] = @url_id">
        <InsertParameters>
            <asp:Parameter Name="usr_id"/>
            <asp:Parameter Name="lst_id"/>
            <asp:Parameter Name="url_isOpen" Type="Boolean" DefaultValue="true"/>
            <asp:Parameter Name="url_name" Type="String"/>
            <asp:Parameter Name="url_address" Type="String"/>
            <asp:Parameter Name="url_sort" Type="Byte" DefaultValue="1"/>
        </InsertParameters>
        <SelectParameters>
            <asp:Parameter Name="usr_id"/>
            <asp:Parameter Name="lst_type_filter" Type="String" DefaultValue="z"/>
        </SelectParameters>
        <UpdateParameters>
            <asp:Parameter Name="lst_id"/>
            <asp:Parameter Name="url_isOpen" Type="Boolean"/>
            <asp:Parameter Name="url_name" Type="String"/>
            <asp:Parameter Name="url_address" Type="String"/>
            <asp:Parameter Name="url_sort" Type="Byte"/>
        </UpdateParameters>
        <DeleteParameters>
            <asp:Parameter Name="url_id"/>
        </DeleteParameters>
    </asp:SqlDataSource>

    <asp:SqlDataSource ID="Sql_Lst" runat="server" OnSelecting="CsSqlSelectingCmb"
    ConnectionString="<%$ ConnectionStrings:Con_Str %>"
        SelectCommand="SELECT [lst_id], [lst_name] 
                       FROM [t_Lists] 
                       WHERE [usr_id] = @usr_id 
                       ORDER BY [lst_sort]">
        <SelectParameters>
            <asp:Parameter Name="usr_id"/>
        </SelectParameters>
    </asp:SqlDataSource> 


    C#:
    ----------------------------------------------------------------------

            protected void Page_Load(object s, EventArgs e)
            {
                _isAuth = HttpContext.Current.User.Identity.IsAuthenticated;

                Sql_Url.SelectCommand = "SELECT b.[lst_id], b.[lst_name], b.[lst_sort], a.[url_id], a.[url_isOpen], a.[url_name], a.[url_address], a.[url_sort] " +
                                        "FROM (SELECT * FROM [t_Urls] WHERE [usr_id] = @usr_id) a " +
                                        "INNER JOIN " +
                                        "(SELECT * FROM [t_Lists] WHERE [usr_id] = @usr_id AND [lst_type] IN ('a', @lst_type_filter)) b " +
                                        "ON a.[lst_id] = b.[lst_id] " +
                                        "ORDER BY b.[lst_sort] ASC, a.[url_sort] ASC, a.[url_date] DESC ";
            }

            protected void CsTlbClick(object s, RadToolBarEventArgs e)
            {
            }

            protected void CsSqlInserting(object s, SqlDataSourceCommandEventArgs e)
            {
                if (_isAuth)
                {
                    e.Command.Parameters["@usr_id"].Value = Membership.GetUser(HttpContext.Current.User.Identity.Name).ProviderUserKey;
                }
                else
                {
                    e.Command.Parameters["@usr_id"].Value = Guid.Empty;
                }
            }

            protected void CsSqlSelecting(object s, SqlDataSourceCommandEventArgs e)
            {

                 e.Command.Parameters["@usr_id"].Value = Membership.GetUser(HttpContext.Current.User.Identity.Name).ProviderUserKey;
                 e.Command.Parameters["@lst_type_filter"].Value = (Session["lst_type"] != null && Session["lst_type"].ToString() != "") ? Session["lst_type"].ToString() : "z";
            }

            protected void CsSqlSelectingCmb(object s, SqlDataSourceCommandEventArgs e)
            {

                e.Command.Parameters["@usr_id"].Value = Membership.GetUser(HttpContext.Current.User.Identity.Name).ProviderUserKey;

            }

    ------------











  2. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1795 posts

    Posted 17 Nov 2014 Link to this post

    Hello Ali,

    The functionality that you are requesting is not available out-of-the-box with templates, but you could take a look at the following Code Library with a sample project, demonstrating how to accomplish the same behavior:
    I could also suggest that you take a look at our built-in checklist filtering functionality:  

    Best Regards,
    Konstantin Dikov
    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.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top