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

Slider.Width property

2 Answers 98 Views
Slider
This is a migrated thread and some comments may be shown as answers.
Michael Dunbar
Top achievements
Rank 2
Michael Dunbar asked on 15 Jun 2009, 03:26 PM
Hello,

I've implemented a slider control that is populated at runtime with a dynamic list of items. It works fine from a code point of view but the UI falls over in some cases when the number items exceeds the width parameter set for the slider. Needing to set this width parameter is essentially the cause of the problem. I want the width to be automatic dependent on the number of items loaded. Is this possible?

My code:

<telerik:RadSlider ID="sldrSurvey" runat="server" /> 

private void PopulateSlider() 
    { 
        sldrSurvey.ItemType = SliderItemType.Item; 
        sldrSurvey.Height = Unit.Pixel(40); 
        sldrSurvey.Width = Unit.Pixel(300); // I don't want to set this 
        sldrSurvey.Skin = "Vista"
 
        HashList<intstring> list = (HashList<intstring>)ValueList; 
        if (list.Count != 0) 
        { 
            foreach (KeyValuePair<intstring> item in list) 
            { 
                 RadSliderItem sliderItem = new RadSliderItem(); 
                 sliderItem.Text = item.Value; 
                 sliderItem.Value = item.Key.ToString(); 
                 sldrSurvey.Items.Add(sliderItem); 
            } 
        } 
 
        sldrSurvey.DataBind(); 
    } 

2 Answers, 1 is accepted

Sort by
0
Tsvetie
Telerik team
answered on 17 Jun 2009, 08:08 AM
Hello Michael Dunbar,
I already answered your question in the support ticket, but I will give the information here as well, so that it is available to all:

***
In case I understand you correctly, you would like to set Width=Unit.Empty and the RadSlider control to calculate its width based on the number of its items. Even though this sounds logical in some cases, in general, this raises some question - e.g. what should be the width of each item (e.g. the width of its text; the width of the longest item text; predefined width; etc.). In my opinion this question has no general answer. For example, in case the control had a property ItemWidth, we could calculate the control width based on this value. However, you will still need to set this ItemWidth property.

As you can set the Width of the RadSlider control dynamically, I would recommend that you set the value of that property based on the number of items you have.
***

Greetings,
Tsvetie
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Michael Dunbar
Top achievements
Rank 2
answered on 17 Jun 2009, 08:20 AM
I see your point, however, the slider is rendered like an unordered list with list items. If you were rendering an unordered list in HTML, you would set the width of the <li> tag to control the items but not the width of the ul unless you wanted it a fixed width. If you don't set the width of the <ul> then, as I am sure you know, it defaults to the width of the parent container. If the width of the item exceeds the <ul> then it wraps.

I suppose to duplicate this behaviour without a default width, I need to set the width to 100%. This doesn't seem possible from the width property. Obviously I see the problem with wrapping a slider control.

Anyway, I decided to change the control that is loaded dynamically to a radio button list, as opposed to a slider, if the number of items exceeds a certain value.

Thanks for your input.
Tags
Slider
Asked by
Michael Dunbar
Top achievements
Rank 2
Answers by
Tsvetie
Telerik team
Michael Dunbar
Top achievements
Rank 2
Share this question
or