Slider value not working as expected

2 posts, 0 answers
  1. Bob Jones
    Bob Jones avatar
    8 posts
    Member since:
    Aug 2009

    Posted 11 Nov 2009 Link to this post

    I am loading a slider from values in a database:

        private void LoadStageSlider(int StageID)  
            bool Found = false;  
            int Min = -1;  
            int Max = -1;  
            Stage s = new Stage();  
            DataView DV = s.List(Master.SiteID, true);  
            foreach (DataRow DR in DV.Table.Rows)  
                int Value = int.Parse(DR["StageID"].ToString());  
                RadSliderItem item = new RadSliderItem(DR["StageName"].ToString(), DR["StageID"].ToString());  
                if (Value == StageID) Found = true;  
                if (Value > Max) Max = Value;  
                if (Min == -1) Min = Value;  
                else if (Value < MinMin = Value;  
            if (Found)  
                slideStage.Value = StageID;  

    Here is the slider declaration:
    <telerik:RadSlider runat="server" ID="slideStage" IsSelectionRangeEnabled="false"   
    Width="450px" Height="40px" Enabled="true" ItemType="Item" TrackPosition="TopLeft" 
    ToolTip="Move the slider to indicate the pipeline stage of this opportunity" 
    Skin="Vista" ShowDecreaseHandle="true" ShowIncreaseHandle="true" /> 

    The StageID values are database Identity values, so they can be just about any number.

    When I load the slider, the slideStage.Value is correct; however when the page displays, the slider is not set to the correct value.
    When I examine slideStage.Value on PostBack, the Value property appears to reflect the Item index, but the SelectedValue property is correct. I saw a reference that said Value on read will contain the Item index, and now I am thoroughly confused.

    Please clarify for me how the Value/SelectedValue properties work and how I can set the slider properties so that it displays the correct value.

    Thanks for any clarity you can shed on this puzzle.
  2. Tsvetie
    Tsvetie avatar
    1517 posts

    Posted 13 Nov 2009 Link to this post

    Hi Bob Jones,
    The Value, the SelectionStart and the SelectionEnd properties work the following way:
    1. In case ItemType=None, the properties set the value(s) of the RadSlider.
    2. In case ItemType=Tick, the properties set the value(s) of the RadSlider.
    3. In case ItemType=Item, the properties set the index or indeces of the selected item(s). The value(s) of the RadSlider in this case is not connected to the value(s) of the selected items - the Value of a slider item is of type string whereas the Value of the RadSlider is of type int. Basically, we cannot change the type of the Value of the RadSlider to string, as in this case, the property would not have any meaning the the first two cases (ItemType=None and ItemType=Tick).
    That is why, in your case, you should set the Value of the RadSlider to the Index of the item you want selected, instead of to the Value of this item:
    slideStage.Value = foundItem.Index;
    Kind regards,
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top