Visualize searched/selected item in RadListBox view area

5 posts, 2 answers
  1. Jesper
    Jesper avatar
    15 posts
    Member since:
    Aug 2011

    Posted 01 Nov 2011 Link to this post

    Hi,
    scenario:
    let's say that I have one RadComboBox (RCB) populated with 10 items (Item1 to Item10) and one RadListBox (RLB) populated with same items. When selecting one item in RCB (AutoPostBack = true) I want that selected value should be selected in RLB and also visualized in RLB:s display area (height set to x px = shows four items). I have succeeded to make the searched item selected in RLB but if I for example searched for Item6 (sorted default 1 to 10) selected item will not be seen in RLB:s view area, it is selected but I need to scroll down to Item6 in RLB to see it. How to get Item6 both selected and seen in RLB:s view area? It's not ok to set index = 0 for Item6 so that it will be seen first in RLB:s list/view area, items needs to be sorted/seen in same order as default (Item1 to Item10).

    Rgds,
    Jesper
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 02 Nov 2011 Link to this post

    Hello Jesper,


    You can try the following javascript.

    JS:
    <script type="text/javascript">
     function OnClientSelectedIndexChanged(sender, args)
     {
       var listbox = $find('<%=RTL.ClientID%>');
       var comboitem = sender.get_selectedItem();
       var items = listbox.get_items();
       for (var i = 0; i < items.get_count(); i++)
        {
          if (comboitem.get_text() == items.getItem(i).get_text())
          {
             items.getItem(i).select()
              items.getItem(i).scrollIntoView(); 
          }
        }
     }
    </script>

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jesper
    Jesper avatar
    15 posts
    Member since:
    Aug 2011

    Posted 04 Nov 2011 Link to this post

    Hi Princy,
    what client event to assign javascript to?

    onclientload and/or onclientselectedindexchanged

     


    I got below error when I have assigned  javascript to above client events

    Compiler Error Message: CS0103: The name 'RTL' does not exist in the current context

    Source Error:

    Line 25:         function OnClientSelectedIndexChanged(sender, args)
    Line 26:         {
    Line 27: var listbox = $find('<%=RTL.ClientID%>');Line 28:             var comboitem = sender.get_selectedItem();
    Line 29:             var items = listbox.get_items();

    How to fix this problem?

    Rgds,
    Jesper
  5. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 04 Nov 2011 Link to this post

    Hello Jesper,

    You can access the ListBox using its ID in the client event OnSelectedIndexChanged of RadCombobox.

    Thanks,
    Princy.
  6. Jesper
    Jesper avatar
    15 posts
    Member since:
    Aug 2011

    Posted 04 Nov 2011 Link to this post

    Hi,
    change

    $find('<%=RTL.ClientID%>');

    to

    $find('RadListBox1');

    correct?

    Rgds,
    Jesper
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017