Skip to content

Infragistics Community Forum / Web / Ultimate UI for ASP.NET Web Forms / First item automatically selected?

First item automatically selected?

New Discussion
Rob
Rob asked on Dec 4, 2017 3:15 PM

I am using a WebDropDown in multiple selection mode and adding items manually in my Page_Load event.

When the page loads, the first item in the list is always automatically selected.  I can not find a way to turn this off.

During a postback, the correct items remain selected/deselected, it’s just that when my page is first loaded, the first item is preselected.

I need to have no items selected on first page load.

Sign In to post a reply

Replies

  • 0
    [Infragistics] Bhadresh Patel
    [Infragistics] Bhadresh Patel answered on Feb 8, 2013 1:56 PM

    Hello,

    I was not able to see the first item selected using NetAdvantage version 12.1.20121.2072 and IE 9. I used below HTML mark up and code to test this:

    HTML MarkUp:

    <ig:WebDropDown ID="WebDropDown1" runat="server" Width="200px" EnableMultipleSelection="True"> </ig:WebDropDown>

    Code:

    DropDownItem wd = new DropDownItem(); wd.Text = "First"; wd.Value = "1"; this.WebDropDown1.Items.Add(wd);

    DropDownItem wd1 = new DropDownItem(); wd1.Text = "Second"; wd1.Value = "2"; this.WebDropDown1.Items.Add(wd1);

    If you want to clear selected items explicitly on page load, I would suggest you to use SelectedItems.Clear(); method as shown below:

     if (!IsPostBack)

    this.WebDropDown1.SelectedItems.Clear();

    I hope this helps.

    • 0
      Rob
      Rob answered on Feb 8, 2013 3:27 PM

      Well, i'm using version 12.1.20121.2020 and IE 8 in Windows XP.  dont know if this makes some sort of difference or not.

      but, anyway, i am adding items in code just as you mentioned.  i also tried unselecting all items in the code behind too, but when i debug, at that point in the code, there are no selected items.

      it's only when the page is rendered on the client that the WDD value is set and the first item is checked.  i don't know where/how it's happening but the only way i could 'fix' it is to use this client event:

      function DropDownInitialize(sender, args) {

        if(<%=(Not Page.IsPostBack).ToString().ToLower()%>){

        sender.set_currentValue('', true);

        sender.get_items().getItem(0).unselect();

      }

       

    • 0
      Rob
      Rob answered on Feb 9, 2013 3:26 AM

      Bhadresh,

      Here is a sample using .NET 3.5 and Infragistics version 12.1.20121.2020.

      This sample demonstrates exactly what I am talking about.

      When the page loads on the client, the first item is automatically selected.

      When I check in the Page_LoadComplete() event on the server, there are zero selected items.

      wvusaf

      WebDropDownAutoSelectFirstItem

      • 0
        [Infragistics] Bhadresh Patel
        [Infragistics] Bhadresh Patel answered on Feb 11, 2013 4:29 PM

        Hello wvusaf,

        Thank you for the sample provided. I was able to see the behavior you described using the sample provided. I reviewed the sample and found this behavior is present when DisplayMode is set to "DropDownList" for WebDropDown.  This behavior is default when DisplayMode is set to "DropDownList". Refer to the link below that will give more details on this:

        http://www.infragistics.com/community/forums/t/50418.aspx

        You can take below approaches to implement the behavior you described:

        1) Set DisplayMode = DropDown, and cancel the ValueChanging client-side event, in case the entry doesn't match an item as shown on the above forum thread.

        2) You can add first item and hide it as shown below:

        Me.WebDropDown1.Items.Insert(0, New DropDownItem(" ", " ", "", "")) Me.WebDropDown1.Items(0).Visible = False

        3) You can handle client side Initialize event of WebDropDown and unselect item and checkbox as shown below:

        function WebDropDown1_Initialize(sender, eventArgs) {  ///<summary>  ///  ///</summary>  ///<param name="sender" type="Infragistics.Web.UI.ControlMain"></param>  ///<param name="eventArgs" type="Infragistics.Web.UI.EventArgs"></param>   

          if (document.readyState == "complete") {

                var item0 = sender.get_items().getItem(0);       

                item0.unselect();    

                item0.get_element().childNodes[0].checked = false;     } }

        I hope this helps.

      • 0
        Rob
        Rob answered on Feb 11, 2013 4:44 PM

        Bhadresh,

        The idea of the Microsoft asp:DropDownList that is mentioned in the other post makes sense.  However, that dropdown is not capable of multi-selection like the Infragistics WebDropDown is.  Once you turn on Multiselect on the ig:WebDropDown, it doesn't make sense to have DisplayMode set to DropDown.  Since each item can be rendered with a checkbox, we know that ALL items will be valid selections.  All you need to be able to do is check the checkbox, so there should be no typing in the WebDropDown at all.  For Multi-select with checkboxes, the only logical DisplayMode is DropDownList so there should be no reason to automatically select the first item in the list in this case.

        wvusaf

      • 0
        [Infragistics] Bhadresh Patel
        [Infragistics] Bhadresh Patel answered on Feb 12, 2013 1:52 PM

        Hello wvusaf,

        I have logged the feature request PI13020057 regarding no selction on DropDown item when DisplayMode is set to "DropDownList" for WebDropDown on your behalf and I have sent that feature request directly to product management team. Our product team chooses new feature requests for development based on popular feedback from our customer base.

        Meanwhile this feature implements, I would recommend you to use one of the approaches I have mentioned in above thread.

        I hope this helps.

      • 0
        Rob
        Rob answered on Feb 12, 2013 2:29 PM

        Bhadresh,

        i ended up implementing the first option you mentioned by setting DisplayMode to DropDown.  Then in the Initialize event for the dropdown, i find the input textbox and set it to readonly.  Also, just to be sure, in the ValueChanging event, i set 'args._cancel = true;' if ''args.get_browserEvent().type == "keyup"'.  This totally prevents any typing any characters in the textbox, which is what i wanted.  I might extend it to try and allow the user to type and match items in the list, but that would be something i do later.

        thanks,

        wvusaf

      • 0
        [Infragistics] Bhadresh Patel
        [Infragistics] Bhadresh Patel answered on Feb 13, 2013 3:02 PM

        Hello wvusaf,

        Thank you for the update. I am just following up to see if you need any further assistance with this matter.

         

      • 0
        David Prasad
        David Prasad answered on Feb 14, 2013 6:01 AM

        Hi wvusaf,

        Can you try giving CurrentValue="" in the markup or code behind. This will make the WebDropDown to display blank

      • 0
        David Prasad
        David Prasad answered on Feb 14, 2013 6:07 AM

        Hi All,

        Apologies, due to some pc/broswer problem, the last two posts became as "Suggested Answer". Not sure how to undo!!

      • 0
        Rob
        Rob answered on Feb 14, 2013 12:44 PM

        This only works when DisplayMode is set to DropDown.  It has no effect when DisplayMode is set to DropDownList, which is the setting that I was using.

      • 0
        [Infragistics] Bhadresh Patel
        [Infragistics] Bhadresh Patel answered on Feb 14, 2013 6:07 PM

        Hello wvusaf,

        Thank you for the update. Feel free to update me if you need any further assistance with this matter.

      • 0
        Pierre Côté
        Pierre Côté answered on Dec 4, 2017 3:15 PM

        Do this feature request has been implemented yet? 4 year later I can't find it.

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Rob
Favorites
0
Replies
13
Created On
Dec 04, 2017
Last Post
8 years, 9 months ago

Suggested Discussions

Created by

Rob

Created on

Dec 4, 2017 3:15 PM

Last activity on

Feb 24, 2026 10:06 PM