2

since I combined an asp:dropdownlist with an asp:checkboxlist, I have the problem in IE(8) and Firefox (Chrome works fine) that everytime I click the DropDownList, the empty box appears in addition to the popup I manually open when the dropdownlist is clicked.

My question now is: How can I hide this empty box (since there are no entries in it), but keep the dropdown element? I don't want to replace this component, since it still should look like a dropdownlist. If I change it to a text box it's not clear anymore that it can be used as a dropdown.

This is what I currently have in place:

<div style="width: 190px;" class="right">
    <!-- the original drop down list -->
    <asp:DropDownList CssClass="dropdownbox" ID="ddlCountry" runat="server">
    </asp:DropDownList>
    <cc1:PopupControlExtender ID="ddlCountry_PopupControlExtender" runat="server" DynamicServicePath=""
        Enabled="True" ExtenderControlID="" TargetControlID="ddlCountry" PopupControlID="pnlPopup"
        OffsetY="20">
    </cc1:PopupControlExtender>
    <!-- Popup control extender that maps the country list to the dropdown list -->
    <asp:Panel ID="pnlPopup" runat="server" CssClass="dropdowncheckbox">
        <!-- List of countries with a checkbox for each entry -->
        <asp:CheckBoxList ID="countryList" runat="server" 
            DataTextField="Countries" DataValueField="Countries" AutoPostBack="True"
            OnSelectedIndexChanged="countryList_SelectedIndexChanged">
        </asp:CheckBoxList>
    </asp:Panel>
</div>

If there is a component that fits my purpose better, please let me know. Thanks a lot in advance for your suggestions.

1
  • Dunno why @IrishChieftain deleted his answer - why indeed can't you disable the dropdown when it is empty? This way user won't be able to click it Commented Oct 24, 2013 at 15:51

4 Answers 4

1

Place this code in the event you need to trigger the change This will work for c#

if(dropdownlist.Items.Count == 0)
{
dropdownlist.Attributes["style"] = "display: none;";
}
else
{
dropdownlist.Attributes["style"] = "";
}
Sign up to request clarification or add additional context in comments.

Comments

0

Simply set the Drop Down List Enabled property to false and toggle it to true when it has entries.

dropdownbox.Enabled = false;

5 Comments

Thanks for your answer, but I don't want it to be disabled, since it should be clickable. When it's clicked, it loads the custom Popup I defined, but shouldn't load its own item list. Basically what I'm doing is faking the menu items with the popup. I just need the Dropdownlist to be there so that the user knows that it can be used as such. I can't use a textbox since several users will definitely not be able to figure out that it can be used like this... I'll try to update the question so that you can visualize it.
Why the need for the popup in the first place?
As mentioned in my last comment, I need something that looks like a dropdown menu, for user convenience and due to space limitations in the according area + some requirements that I can't change. I thought about using a multiselect list, but it couldn't be higher than 1 line, so I'm back to square 1. I'm very happy for other suggestions if there are other components that do the same thing. But for what I need (a dropdownlist with checkboxes for each entry), I couldn't find somethinge proper other than this.
You can't reinvent UI elements. My advice is to make room and use the drop down list as it's meant to be used :-)
Well I guess then I have to go with that approach since I'm running out of time, although it's a bit disappointing that there is no real DropDownCheckboxList :( Thanks for your answers anyway, I will however try to update this case if I find something better during my research.
0

do something like this in c#:

if(dropdownlist.Items.Count == 0)
{
      dropdownlist.Visible = false;
}
else
{
      dropdownlist.Visible = true;
}

1 Comment

Thanks for your answer, however the list needs to be clickable and visible when the menu is shown. In this case this wouldn't be possible anymore, I think.
0

Encapsulate the dropdown in a div, give the div an id and the runat="server" property

Check in the code behind of the data to load the dropdown is empty set the div to visible false; if not, set the div to visible true.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.