Hide drop down if no items found

7 posts, 0 answers
  1. Duncan
    Duncan avatar
    93 posts
    Member since:
    Jul 2012

    Posted 14 Feb 2012 Link to this post

    Is there a way to hide the drop down of the RadCombo box if no items are found during the search?

    Thanks,
    Duncan
  2. jumpstart
    jumpstart avatar
    479 posts
    Member since:
    Nov 2011

    Posted 15 Feb 2012 Link to this post

    Duncan:

    This topic is covered in-depth in the following forum thread:

    How to disable dropdown when not databound?

    Cheers!
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Duncan
    Duncan avatar
    93 posts
    Member since:
    Jul 2012

    Posted 15 Feb 2012 Link to this post

    I'm sorry but that solution does not seem to work for me...

    <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
        <script type="text/javascript">
            function OnClientDropDownOpening(sender, eventArgs) {
                var combo = $find("<%= cboTags.ClientID %>");
                items = combo.get_items();
                if (items.get_count() == 0) {
                    eventArgs.set_cancel(true);
                }
            }
        </script>
    </telerik:RadScriptBlock>

    <telerik:RadComboBox ID="cboTags" runat="server" CssClass="combo" AutoPostBack="true"
        Width="394px" EnableEmbeddedBaseStylesheet="False" EnableEmbeddedSkins="False"
        EnableTheming="False" ItemsPerRequest="8" MarkFirstMatch="True" ShowMoreResultsBox="True"
        ShowToggleImage="False" EmptyMessage="Tag Name" DropDownCssClass="combo-input-drop"
        Filter="Contains" DropDownWidth="410" EnableAutomaticLoadOnDemand="False" EnableLoadOnDemand="True"
        OffsetX="-38" OffsetY="-3" ShowDropDownOnTextboxClick="False" DataTextField="Tag"
        DataValueField="TagId" EnableTextSelection="False" NoWrap="True" AllowCustomText="True"
        Height="208" OnItemsRequested="cboTags_ItemsRequested" ValidationGroup="Form"
        OnClientItemsRequested="OnClientDropDownOpening">
    </telerik:RadComboBox>

  5. jumpstart
    jumpstart avatar
    479 posts
    Member since:
    Nov 2011

    Posted 15 Feb 2012 Link to this post

    Duncan:

    Can you post your .aspx markup and code behind so that we can better understand your scenario?

    Regards,
  6. Duncan
    Duncan avatar
    93 posts
    Member since:
    Jul 2012

    Posted 15 Feb 2012 Link to this post

    <%@ Page Title="" Language="C#" MasterPageFile="~/App_Master/Application.master"
        AutoEventWireup="true" CodeFile="Manage.aspx.cs" Inherits="Admin_Tags_Manage" %>
     
    <asp:Content ID="Content1" ContentPlaceHolderID="ph_head" runat="Server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ph_content" runat="Server">
        <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
            <script type="text/javascript">
                function OnClientDropDownOpening(sender, eventArgs) {
                    var combo = $find("<%= cboTags.ClientID %>");
                    items = combo.get_items();
                    if (items.get_count() == 0) {
                        eventArgs.set_cancel(true);
                    }
                }
            </script>
        </telerik:RadScriptBlock>
        <telerik:RadAjaxLoadingPanel ID="loadingpanelFull" runat="server" Skin="" Transparency="30"
            CssClass="loading">
            <div class="full">
            </div>
        </telerik:RadAjaxLoadingPanel>
        <telerik:RadAjaxPanel ID="radAjaxPanel" runat="server" LoadingPanelID="loadingpanelFull">
            <asp:Panel ID="pnlOverlay" runat="server" Visible="false">
                <div class="sample_data_overlay">
                     </div>
                <div class="sample_data_popup">
                    <h4>
                        <asp:Label ID="lblPopupHeader" runat="server" />
                    </h4>
                    <p>
                        <asp:Label ID="lblPopupText" runat="server" /></p>
                    <asp:Panel ID="pnlActionButton" runat="server">
                        <asp:HyperLink ID="lnkPopupAction" runat="server" />
                    </asp:Panel>
                </div>
            </asp:Panel>
            <asp:Repeater ID="rptChoicesMenu" runat="server" OnItemCommand="ChoicesMenu_ItemCommand"
                OnItemDataBound="ChoicesMenu_ItemDataBound">
                <HeaderTemplate>
                    <ul class="contentchoices">
                </HeaderTemplate>
                <ItemTemplate>
                    <li id="ListItem" runat="server">
                        <asp:LinkButton ID="btnItem" runat="server" /></li>
                </ItemTemplate>
                <FooterTemplate>
                    </ul></FooterTemplate>
            </asp:Repeater>
            <asp:Panel ID="pnlEditOverlay" runat="server" Visible="false">
                <div class="sample_data_overlay">
                     </div>
                <div class="sample_data_popup">
                    <h4>
                        Edit This Tag:</h4>
                    <p>
                        Please edit the tag and its related tags below.</p>
                    <table border="0" cellspacing="0" cellpadding="0" class="editform">
                        <tr>
                            <td>
                                <telerik:RadTextBox ID="txtTag" runat="server" class="textbox" EnableEmbeddedBaseStylesheet="False"
                                    EnableEmbeddedSkins="False" EnableTheming="False" EmptyMessage="Tag Name" />
                            </td>
                        </tr>
                        <tr>
                            <th>
                                Add/Remove Related Tags:
                            </th>
                        </tr>
                        <tr>
                            <td>
                                <div class="withbutton">
                                    <asp:HiddenField ID="hdnCurrentTagId" runat="server" />
                                    <telerik:RadComboBox ID="cboTags" runat="server" CssClass="combo" AutoPostBack="true"
                                        Width="394px" EnableEmbeddedBaseStylesheet="False" EnableEmbeddedSkins="False"
                                        EnableTheming="False" ItemsPerRequest="8" MarkFirstMatch="True" ShowMoreResultsBox="True"
                                        ShowToggleImage="False" EmptyMessage="Tag Name" DropDownCssClass="combo-input-drop"
                                        Filter="Contains" DropDownWidth="410" EnableAutomaticLoadOnDemand="False" EnableLoadOnDemand="True"
                                        OffsetX="-38" OffsetY="-3" ShowDropDownOnTextboxClick="False" DataTextField="Tag"
                                        DataValueField="TagId" EnableTextSelection="False" NoWrap="True" AllowCustomText="True"
                                        Height="208" OnItemsRequested="cboTags_ItemsRequested" ValidationGroup="Form"
                                        OnClientItemsRequested="OnClientDropDownOpening">
                                    </telerik:RadComboBox>
                                </div>
                                <div class="add">
                                    <asp:LinkButton ID="btnAdd" runat="server" OnClick="btnAdd_Click" ValidationGroup="Form" />
                                </div>
                            </td>
                        </tr>
                        <asp:Repeater ID="rptRelatedTags" runat="server" OnItemCommand="Tags_ItemCommand"
                            OnItemDataBound="Tags_ItemDataBound">
                            <ItemTemplate>
                                <tr>
                                    <td class="urlcell">
                                        <div class="withbutton">
                                            <asp:LinkButton ID="btnTag" runat="server" CommandName="edit" CausesValidation="False" /></div>
                                        <div class="remove">
                                            <asp:LinkButton ID="btnRemove" runat="server" CommandName="remove" CausesValidation="False" /></div>
                                    </td>
                                </tr>
                            </ItemTemplate>
                        </asp:Repeater>
                        <tr>
                            <th>
                                Other Tags Relating:
                            </th>
                        </tr>
                        <asp:Repeater ID="rptRelatingTags" runat="server" OnItemCommand="Tags_ItemCommand"
                            OnItemDataBound="Tags_ItemDataBound">
                            <ItemTemplate>
                                <tr>
                                    <td class="urlcell">
                                        <div class="withbutton">
                                            <asp:LinkButton ID="btnTag" runat="server" CommandName="edit" CausesValidation="False" /></div>
                                        <div class="add">
                                            <asp:LinkButton ID="btnAdd" runat="server" CommandName="add" CausesValidation="False" /></div>
                                    </td>
                                </tr>
                            </ItemTemplate>
                        </asp:Repeater>
                    </table>
                    <asp:Panel ID="pnlSaveButton" runat="server">
                        <asp:LinkButton ID="btnSave" runat="server" OnClick="btnSave_Click" />
                    </asp:Panel>
                    <div class="cancel">
                        <asp:LinkButton ID="btnCancel" runat="server" Text="Cancel" OnClick="btnCancel_Click" /></div>
                </div>
            </asp:Panel>
            <div class="clearfloat">
            </div>
            <h1>
                New Tags Added</h1>
            <div class="stat-fullgraph">
                <div class="graph">
                    <asp:Image ID="imgTagsAdded" runat="server" /></div>
            </div>
            <div class="clearfloat">
            </div>
            <h1>
                Manage Tags</h1>
            <div class="clearfloat">
            </div>
            <table border="0" cellspacing="0" cellpadding="0" class="datatable">
                <tr>
                    <td>
                        <div class="header">
                            <div class="text">
                                The selected tags have related tags</div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td class="typerow">
                        Tags:
                    </td>
                </tr>
                <asp:Repeater ID="rptItems" runat="server" OnItemDataBound="rptItems_ItemDataBound"
                    OnItemCommand="rtpItems_ItemCommand">
                    <ItemTemplate>
                        <tr>
                            <td>
                                <table border="0" cellspacing="0" cellpadding="0">
                                    <tr class="trhover">
                                        <td class="checkcol">
                                            <asp:CheckBox ID="chkHasRelated" runat="server" AutoPostBack="True" Enabled="false" />
                                        </td>
                                        <td class="admin-itemcol">
                                            <div>
                                                <asp:LinkButton ID="btnItemName" CommandName="edit" runat="server" />  <asp:Label
                                                    ID="lblProfileFullName" runat="server" /></div>
                                        </td>
                                        <td class="admin-approvecol">
                                            <asp:LinkButton ID="btnApprove" runat="server" CommandName="approve" Text="Approve" />
                                        </td>
                                        <td class="admin-removecol">
                                            <asp:LinkButton ID="btnRemove" runat="server" CommandName="remove" Text="Remove" />
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </ItemTemplate>
                </asp:Repeater>
            </table>
        </telerik:RadAjaxPanel>
    </asp:Content>

    The relevant parts of the code behind are:
    protected void cboTags_ItemsRequested(object sender, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e)
    {
        Tags_DataBind();
    }

    public void Tags_DataBind()
    {
        TagsBL tagsbl = new TagsBL(conn);
     
        cboTags.DataSource = tagsbl.GetAllTags(contextuser);
        cboTags.DataBind();
        cboTags.SortItems();
    }
  7. jumpstart
    jumpstart avatar
    479 posts
    Member since:
    Nov 2011

    Posted 15 Feb 2012 Link to this post

    Duncan:

    Why not simply check to see if your RadComboBox.Item.Count == 0 after binding it, and if so, set RadComboBox.Enabled = false.

    This simple mock up worked for me when the XML source file contains no items:
    using Telerik.Web.UI;
     
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                RadComboBox1.LoadContentFile("combobox2.xml");
     
                if (RadComboBox1.Items.Count == 0)
                {
                    RadComboBox1.Enabled = false;
                }
            }       
     
        }
    }

    Hope this helps!
  8. Duncan
    Duncan avatar
    93 posts
    Member since:
    Jul 2012

    Posted 16 Feb 2012 Link to this post

    I'm not sure that would work with EnableLoadOnDemand set to true as there are always items being bound but not always being shown... if that makes sense...
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017