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

RadListBox Height

3 Answers 305 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Michael Landy
Top achievements
Rank 1
Michael Landy asked on 10 Mar 2010, 12:43 AM
I would like to set the height of the listbox to show 5 rows of data.  The rows are simple text entries using RadListBoxItem.  In order to set the height, it seems like I would have to calculate the height of one item and multiple that by the number of rows that I want to show.  Then, set the height of the listbox to this value.

The "height" property for the RadListItem is blank before adding to a listbox, after adding to a listbox, and after adding to an update panel on the page.  I kind of figured this was the case given that the style sheet may cause the size to change.

So, how should I set the height of a listbox assuming I want to show 5 items at a time?  Do I calculate it on the server side using best guess at the row size?  How well does that work for cross browser implementations?  Do I calculate it on the client side in javascript?

What would be the best approach to this?

Thanks

Michael

3 Answers, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 10 Mar 2010, 05:01 PM
Hello Michael Landy,


I suggest you subscribe to OnClientLoad event of the listbox and calculate the height in its handler:

<script type="text/javascript">
    function listBoxLoad(sender, args) {
        var elementHeight = $telerik.getSize(sender.get_items().getItem(0).get_element()).height;
        sender._groupElement.style.height = (elementHeight*5) + "px";
    }
</script>

also you should add the following css styles to your page:

<style type="text/css">
    .rlbGroup, .rlbList { overflow: auto !important; }
</style>

Best regards,
Yana
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Slava
Top achievements
Rank 1
answered on 25 May 2016, 06:14 PM

Yana is great, boys.

sender._groupElement has appeared to be important undocumented thing here.

I tried get_element(), get_childElement() and neigher worked well.

 

0
Ivan Danchev
Telerik team
answered on 30 May 2016, 11:18 AM
Hello Slava,

_groupElement
is a private property, that is why it is not mentioned in the documentation. In the code snippet posted by Yana it can be replaced by the public get_childListElement() client-side method:
sender.get_childListElement().style.height = (elementHeight * 5) + "px";

Regards,
Ivan Danchev
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
ListBox
Asked by
Michael Landy
Top achievements
Rank 1
Answers by
Yana
Telerik team
Slava
Top achievements
Rank 1
Ivan Danchev
Telerik team
Share this question
or