
Voss Grose
Top achievements
Rank 1
Voss Grose
asked on 25 Jan 2009, 04:55 PM
I've posted this before, but the solution did not work.
I cannot get the value of the selected item in the slider control on post back.
I just give me the index of the selected item.
I must have some strange setting or doing something crazy because this must work:
Below is the slider control I've used for testing and on a simple button click (server side) I cannot get the correct value. Just gives me the index.
I'm using the latest version of the telerik controls.
<telerik:RadSlider runat="server" ID="rsVery" EnableViewState="true" Orientation="Horizontal" Width="500" Height="50" TrackPosition="TopLeft" Skin="Inox" ItemType="Item" SmallChange="1" ShowDecreaseHandle="true" ShowIncreaseHandle="true" AnimationDuration="250">
<Items>
<telerik:RadSliderItem Text="Very Slow" Value="22" ToolTip="Very Slow" runat="server"></telerik:RadSliderItem>
<telerik:RadSliderItem Text="Slow" Value="33" runat="server"></telerik:RadSliderItem>
<telerik:RadSliderItem Text="Normal" Value="44" runat="server"></telerik:RadSliderItem>
<telerik:RadSliderItem Text="Fast" Value="55" runat="server"></telerik:RadSliderItem>
<telerik:RadSliderItem Text="Very Fast" Value="66" runat="server"></telerik:RadSliderItem>
</Items>
</telerik:RadSlider>
I cannot get the value of the selected item in the slider control on post back.
I just give me the index of the selected item.
I must have some strange setting or doing something crazy because this must work:
Below is the slider control I've used for testing and on a simple button click (server side) I cannot get the correct value. Just gives me the index.
I'm using the latest version of the telerik controls.
<telerik:RadSlider runat="server" ID="rsVery" EnableViewState="true" Orientation="Horizontal" Width="500" Height="50" TrackPosition="TopLeft" Skin="Inox" ItemType="Item" SmallChange="1" ShowDecreaseHandle="true" ShowIncreaseHandle="true" AnimationDuration="250">
<Items>
<telerik:RadSliderItem Text="Very Slow" Value="22" ToolTip="Very Slow" runat="server"></telerik:RadSliderItem>
<telerik:RadSliderItem Text="Slow" Value="33" runat="server"></telerik:RadSliderItem>
<telerik:RadSliderItem Text="Normal" Value="44" runat="server"></telerik:RadSliderItem>
<telerik:RadSliderItem Text="Fast" Value="55" runat="server"></telerik:RadSliderItem>
<telerik:RadSliderItem Text="Very Fast" Value="66" runat="server"></telerik:RadSliderItem>
</Items>
</telerik:RadSlider>
7 Answers, 1 is accepted
0
Hello Voss Grose,
As already mentioned in the other thread you started with the same question, the Value property of the RadSlider gets the index of the selected item, when you use ItemType=Item. This is by design and we decided to implement the RadSlider that way, so that you can set not only integers as Value for a RadSlider item, but strings as well. When you get the index of the selected item, you can use it to get a reference to the item itself and then get its Value.
For example (this code was posted in the other forum thread and demonstrated what you need to do in VB):
or:
In case you still have problems getting the value of the selected item, please prepare and send us a simple running project, demonstrating the problem, together with detailed information on the expected result.
Kind regards,
Tsvetie
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
As already mentioned in the other thread you started with the same question, the Value property of the RadSlider gets the index of the selected item, when you use ItemType=Item. This is by design and we decided to implement the RadSlider that way, so that you can set not only integers as Value for a RadSlider item, but strings as well. When you get the index of the selected item, you can use it to get a reference to the item itself and then get its Value.
For example (this code was posted in the other forum thread and demonstrated what you need to do in VB):
Dim slider As RadSlider = TryCast(item.FindControl("rslider"), Telerik.Web.UI.RadSlider) |
Dim value As Integer = slider.Value |
Dim routsegid As String = slider.Items(value).Value.ToString() |
or:
int value = rsVery.Value; |
string routsegid = rsVery.Items[value].Value; |
In case you still have problems getting the value of the selected item, please prepare and send us a simple running project, demonstrating the problem, together with detailed information on the expected result.
Kind regards,
Tsvetie
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0

Voss Grose
Top achievements
Rank 1
answered on 30 Jan 2009, 07:55 PM
Thanks for the reply, but I still do not understand why it's implemented in this fashion.
An asp DropDownList(like many controls) has a selectedvalue as type String.
Why wouldn't the slider work the same way?
It seems as though it should always return a string and it should be up to the developer to convert the value.
Maybe I'm not understanding something...but it seems kind of a hack to have to retrieve the value in this manner.
An asp DropDownList(like many controls) has a selectedvalue as type String.
Why wouldn't the slider work the same way?
It seems as though it should always return a string and it should be up to the developer to convert the value.
Maybe I'm not understanding something...but it seems kind of a hack to have to retrieve the value in this manner.
0
Hi Voss Grose,
Besides the reason, I have already provided in the other forum thread, namely:
***
We made this on purpose, so that the developers have more flexibility and can define sliders like the following one:
***
, our decision was based on the following ones as well:
Best wishes,
Tsvetie
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Besides the reason, I have already provided in the other forum thread, namely:
***
We made this on purpose, so that the developers have more flexibility and can define sliders like the following one:
<telerik:RadSlider ID="MonthsSlider" runat="server" Orientation="Vertical" Skin="SkyBlue" |
Height="417px" Width="100px" CssClass="monthsSlider" ItemType="Item" TrackPosition="TopLeft" |
Value="5" OnClientValueChange="MonthChange"> |
<Items> |
<telerik:RadSliderItem Text="January" Value="Jan" /> |
<telerik:RadSliderItem Text="February" Value="Feb" /> |
<telerik:RadSliderItem Text="March" Value="Mar" /> |
<telerik:RadSliderItem Text="April" Value="Apr" /> |
<telerik:RadSliderItem Text="May" Value="May" /> |
<telerik:RadSliderItem Text="June" Value="Jun" /> |
<telerik:RadSliderItem Text="July" Value="Jul" /> |
<telerik:RadSliderItem Text="August" Value="Aug" /> |
<telerik:RadSliderItem Text="September" Value="Sep" /> |
<telerik:RadSliderItem Text="October" Value="Oct" /> |
<telerik:RadSliderItem Text="November" Value="Nov" /> |
<telerik:RadSliderItem Text="December" Value="Dec" /> |
</Items> |
</telerik:RadSlider> |
***
, our decision was based on the following ones as well:
- The RadSlider should work in a consistent way:
- It should return only Integers when it has ItemType=None. That is why it should return an Integer, no matter what the value of the ItemType property is.
- The MinumumValue, MaximumValue and SmallChange, which are all of Int type, should have meaning even in case ItemType=Item.
- The RadSlider should be backwards compatible - otherwise, we will break the code of our customers in case they decide to upgrade. As the Value property was of type Int before we implemented the ItemType property, we would not change its type. This is not applicable in case the change is a must, which is not the case.
- Even though the RadSlider resembles a DropDownList in many ways, in this particular case, the DropDownList lacks the features that the RadSlider has, based on which we have decided to implement the Value property in this manner.
Best wishes,
Tsvetie
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0

Voss Grose
Top achievements
Rank 1
answered on 08 Feb 2009, 01:36 AM
Follow up:
How do I set the value?
So I get the value back from a Db...how do I set the value of a slider control?
thanks.
How do I set the value?
So I get the value back from a Db...how do I set the value of a slider control?
thanks.
0
Hello Voss Grose,
You can set the value of the RadSlider control using its Value property. In case you get the value of the RadSliderItem, you will have to get the index of that item and set it as Value of the RadSlider.
All the best,
Tsvetie
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
You can set the value of the RadSlider control using its Value property. In case you get the value of the RadSliderItem, you will have to get the index of that item and set it as Value of the RadSlider.
All the best,
Tsvetie
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0

Voss Grose
Top achievements
Rank 1
answered on 10 Feb 2009, 05:38 PM
Can you please give me a code exmaple of setting the value?
I've tried it using the index, but it dose not work for me.
I would like an example for the following:
Slider with the following items (-10, -5. 0, 5, 10)
Obviously I'm not going to store the index in the Db so I'll store "5" (selected value)
In the code I'll retrive "5" from the Db and locate the index as 3.
It's the actual setting of the value I cannot get to work.
Do not worry about what my code looks like...I would like a working example if you could provide it.
thanks.
I've tried it using the index, but it dose not work for me.
I would like an example for the following:
Slider with the following items (-10, -5. 0, 5, 10)
Obviously I'm not going to store the index in the Db so I'll store "5" (selected value)
In the code I'll retrive "5" from the Db and locate the index as 3.
It's the actual setting of the value I cannot get to work.
Do not worry about what my code looks like...I would like a working example if you could provide it.
thanks.
0
Hello,
Have a look at the following code fragment:
code-behind:
In case this does not help you, please open a new support ticket and send us a simple running project, demonstrating your setup, together with detailed information what you are trying to achieve.
Kind regards,
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.
Have a look at the following code fragment:
<telerik:RadSlider ID="RadSlider1" runat="server" |
ItemType="Item" Height="70px" TrackPosition="TopLeft"> |
<Items> |
<telerik:RadSliderItem Text="-10" Value="-10" /> |
<telerik:RadSliderItem Text="-5" Value="-5" /> |
<telerik:RadSliderItem Text="0" Value="0" /> |
<telerik:RadSliderItem Text="5" Value="5" /> |
<telerik:RadSliderItem Text="10" Value="10" /> |
</Items> |
</telerik:RadSlider> |
<asp:Button ID="Button1" runat="server" Text="SetValueTo_'5'" OnClick="Button1_Click" /> |
code-behind:
protected void Button1_Click(object sender, EventArgs e) |
{ |
string selectedValue = "5"; |
for (int i = 0; i < RadSlider1.Items.Count; i++) |
{ |
RadSliderItem item = RadSlider1.Items[i]; |
if (item.Value == selectedValue) |
{ |
RadSlider1.Value = item.Index; break; |
} |
} |
} |
In case this does not help you, please open a new support ticket and send us a simple running project, demonstrating your setup, together with detailed information what you are trying to achieve.
Kind regards,
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.