<telerik:RadSlider runat="server" ID="rsVery" EnableViewState="false" Orientation="Horizontal" Width="500" Height="50" TrackPosition="TopLeft" Skin="Inox" ItemType="Item" MinimumValue="-10" MaximumValue="10" SmallChange="1" ShowDecreaseHandle="true" ShowIncreaseHandle="true" Visible="true" AnimationDuration="250">
<Items>
<telerik:RadSliderItem Text="Very Slow" Value="-3" ToolTip="Very Slow" runat="server"></telerik:RadSliderItem>
<telerik:RadSliderItem Text="Slow" Value="-2" runat="server"></telerik:RadSliderItem>
<telerik:RadSliderItem Text="Normal" Value="0" runat="server"></telerik:RadSliderItem>
<telerik:RadSliderItem Text="Fast" Value="2" runat="server"></telerik:RadSliderItem>
<telerik:RadSliderItem Text="Very Fast" Value="3" runat="server"></telerik:RadSliderItem>
</Items>
</telerik:RadSlider>
The .Value just returns the position index.
can you tell me what I'm doing wrong..
thanks
14 Answers, 1 is accepted
Dim sli As RadSlider = TryCast(item.FindControl("rslider"), Telerik.Web.UI.RadSlider)
Dim value As Integer = sli.Value
Dim routsegid As String = sli.Items(value).Value.ToString()
use the slider value (index) to get the selected slideritem. Then get the value of the item.
Yes, this is the correct way to obtain the value of the currently selected item of the RadSlider. By design, when you have items in the RadSlider, the slider itself can accept values from 0 to the number of the items minus 1. 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> |
Greetings,
Tsvetie
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Slider.SelectedItem as a public property that acts as a wrapper for
slider.Items[slider.Value]
So rather than in code having to do:
sldSlider1.Items[sldSlider1.Value].Value
I can just do:
sldSlider1.SelectedItem.Value
it's elegance really, functionally it makes little difference, but aesthetically in code and logically I think it's better?
that said, if there is already something like this, please ignore the post - I just haven't managed to find it.
Cheers,
Terry
There is such a server property - SelectedItems, however, it is not implemented yet. We will do our best to implement it for the SP, scheduled for this week.
All the best,
Tsvetie
the Telerik team
Check out Telerik Trainer , the state of the art learning tool for Telerik products.
I want a label next to the slider to show the selected value as the user slides the slider. This takes to long if it has to be done server-side. I see in the generated HTML that the LI tags do not have any reference to the values, only the indexes. Is there a way around this?
You can get the value of a slider item on the client in a similar manner as on the server:
function GetItemValue() |
{ |
var slider = $find('<%= RadSlider1.ClientID %>'); |
var selectedItem = slider.get_items()[slider.get_value()]; |
alert(selectedItem.get_value()); |
} |
All the best,
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.
Thank you for your response. However, the code you suggested gets only the numeric index of the slider position, not the value of that index. In the code below, I want the text for each item, not the numeric index.
<telerik:RadSlider ID="RadSlider" runat="server" MaximumValue="7"
Width="300px" Height="22px" Length="300" ItemType="Tick" onclientslide="OnSlide" >
<Items>
<telerik:RadSliderItem runat="server" Text="Not Set" Value="Not Set" />
<telerik:RadSliderItem runat="server" Text="Very unhappy" Value="Very unhappy" />
<telerik:RadSliderItem runat="server" Text="Unhappy" Value="Unhappy" />
<telerik:RadSliderItem runat="server" Text="Somewhat unhappy" Value="Somewhat unhappy" />
<telerik:RadSliderItem runat="server" Text="Neutral" Value="Neutral" />
<telerik:RadSliderItem runat="server" Text="Somewhat satisfied" Value="Somewhat satisfied" />
<telerik:RadSliderItem runat="server" Text="Satisfied" Value="Satisfied" />
<telerik:RadSliderItem runat="server" Text="Very satisfied" Value="Very satisfied" />
</Items>
</telerik:RadSlider>
Tony
In case you need to text of a slider item, you should use the get_text method:
function GetItemValue() |
{ |
var slider = $find('<%= RadSlider1.ClientID %>'); |
var selectedItem = slider.get_items()[slider.get_value()]; |
alert(selectedItem.get_text()); |
} |
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.
function OnSlide() |
{ |
var slider = $find('<%= RadSlider.ClientID %>'); |
var selectedItem = slider.get_items()[slider.get_value()]; |
document.getElementById('GoodFeeling').innerText = selectedItem.get_text(); |
} |
Tony
I am not quite sure what you mean by index number. When I run the provided code for the following RadSlider, I get January, February, March, etc:
<script type="text/javascript"> |
function OnSlide(sender, args) |
{ |
var slider = sender; |
var selectedItem = slider.get_items()[slider.get_value()]; |
document.getElementById('GoodFeeling').innerText = selectedItem.get_text(); |
} |
</script> |
<div id="GoodFeeling"> |
</div> |
<telerik:RadSlider ID="RadSlider1" runat="server" ItemType="Item" Width="700px" Height="70px" |
TrackPosition="BottomRight" OnClientSlide="OnSlide"> |
<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> |
As I am not sure which version of the assembly you use, I tested with the latest - 2009.1.402.
In case this does not help you, please prepare and send me a simple running project, demonstrating the problem as well as detailed information on the expected result.
Best wishes,
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.
slider.get_items is undefined. Has something changed? How can I get the current text of the item at the specified index?
I've isolated this demo,
http://demos.telerik.com/aspnet-ajax/slider/examples/clientsideevents/defaultvb.aspx?show-source=true
I changed javascript code as follows: It does not work.
rangeSliderValueChanging: function (sender, args) {
var newValue = args.get_newValue();
var isFirstHandleActive = getActiveDragHandle(sender);
var slider = sender;
var selectedItem = slider.get_items()[slider.get_value()];
alert(selectedItem.get_text());
},