This is a migrated thread and some comments may be shown as answers.

Visualize searched/selected item in RadListBox view area

4 Answers 76 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Jesper
Top achievements
Rank 1
Jesper asked on 01 Nov 2011, 08:42 PM
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

4 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 02 Nov 2011, 07:12 AM
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.
0
Jesper
Top achievements
Rank 1
answered on 04 Nov 2011, 11:48 AM
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
0
Accepted
Princy
Top achievements
Rank 2
answered on 04 Nov 2011, 12:27 PM
Hello Jesper,

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

Thanks,
Princy.
0
Jesper
Top achievements
Rank 1
answered on 04 Nov 2011, 01:07 PM
Hi,
change

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

to

$find('RadListBox1');

correct?

Rgds,
Jesper
Tags
ListBox
Asked by
Jesper
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Jesper
Top achievements
Rank 1
Share this question
or