Slider.Width property

3 posts, 0 answers
  1. Michael Dunbar
    Michael Dunbar avatar
    129 posts
    Member since:
    Sep 2007

    Posted 15 Jun 2009 Link to this post

    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. Tsvetie
    Admin
    Tsvetie avatar
    1517 posts

    Posted 17 Jun 2009 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Michael Dunbar
    Michael Dunbar avatar
    129 posts
    Member since:
    Sep 2007

    Posted 17 Jun 2009 Link to this post

    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.
Back to Top