Selecting first item after binding combo

5 posts, 1 answers
  1. Mansi
    Mansi avatar
    63 posts
    Member since:
    Feb 2009

    Posted 03 Mar 2010 Link to this post

    Hi,

    I have one radcomobobox, on its selectedindexchanged event, I am binding it with new values.
    It is ok when I bind it first time, it do show the first item selected. But when the selectedindexchanged event fires, it still shows the previously selected item (only text, when I click on comobo, it shows the new item selected), even though I assign selected index every time on binding.

    Below is a code of binding.

      for (i = 0; i <= dtable.Rows.Count - 1; i++) 
         { 
           DDEvent.Items.Add(new RadComboBoxItem("text", "value"); 
         } 
       DDEvent.SelectedIndex = 0 
     
     

    I tried this too after the above code, but still not done.

          DDEvent.SelectedItem.Text = DDEvent.Items(0).Text
  2. robertw102
    robertw102 avatar
    265 posts
    Member since:
    Jul 2007

    Posted 03 Mar 2010 Link to this post

    I don't understand your situation. Are you saying that you bind the values of the RadComboBox in its SelectedIndexChanged event? I don't understand why you would be binding the RadComboBoxes values in that event.

    Also, the reason it won't show the item you set as the SelectedIndex is because after the event finishes, I believe it then sets the index that was selected as the selected item or the selected text.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Mansi
    Mansi avatar
    63 posts
    Member since:
    Feb 2009

    Posted 04 Mar 2010 Link to this post

    Hi,
    Thanks for the reply.
    I explain again. Find attached image.

    I have two combos. On the selectedindexchanged event of the first comobo, I am filling the second comobo and selecting the first item of the filled comobo.

    First time I do this on page load, and everything works fine. But then, when I change the item in first comobo, it fills the second combo properly.
    But in second combo after fill, it still shows the text, which was previously selected, not the first item from the filled items. And I need to select it only by its index, which should be 0.
  5. Answer
    robertw102
    robertw102 avatar
    265 posts
    Member since:
    Jul 2007

    Posted 04 Mar 2010 Link to this post

    Does your second combobox have the AllowCustomText="true" property set? It sounds like that may be the reason the text still persists after you select the next item or maybe I'm wrong. Either way, why not try clearing the text of the second combobox before populating it and see if that helps.

    Like so:
    RadComboBox2.Text = ""
  6. Mansi
    Mansi avatar
    63 posts
    Member since:
    Feb 2009

    Posted 05 Mar 2010 Link to this post

    Hi,

    Thanks, It worked.

    I didn't set AllowCustomText="true".

    Before binding I was clearing items of combo, but was not setting the text.

    RadComboBox2.Text = "" worked.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017