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

Slider value not working as expected

1 Answer 82 Views
Slider
This is a migrated thread and some comments may be shown as answers.
Bob Jones
Top achievements
Rank 1
Bob Jones asked on 12 Nov 2009, 12:11 AM

I am loading a slider from values in a database:

    private void LoadStageSlider(int StageID)  
    {  
        bool Found = false;  
        int Min = -1;  
        int Max = -1;  
        slideStage.Items.Clear();  
        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());  
            slideStage.Items.Add(item);  
            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.

1 Answer, 1 is accepted

Sort by
0
Tsvetie
Telerik team
answered on 13 Nov 2009, 03:19 PM
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,
Tsvetie
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.
Tags
Slider
Asked by
Bob Jones
Top achievements
Rank 1
Answers by
Tsvetie
Telerik team
Share this question
or