Simple question about getting max value

4 posts, 0 answers
  1. Aron
    Aron avatar
    80 posts
    Member since:
    Dec 2005

    Posted 10 Aug 2009 Link to this post

    Hello
    How do I get the selected value, in this case I believe you would also call it the max value
    <telerik:RadSlider AutoPostBack="True" ID="RadSliderPrice" Width="650"  
                    runat="server"  Height="35px" MinimumValue="5" Orientation="Horizontal" TrackPosition="BottomRight" 
                    MaximumValue="5000" onvaluechanged="RadSliderPrice_ValueChanged" AnimationDuration="400" CssClass="ItemsSlider" 
                    Value="25" ItemType="Item" > 
                    <Items> 
                        <telerik:RadSliderItem runat="server" Text="$5" Value="5" /> 
                        <telerik:RadSliderItem runat="server" Text="$10" Value="10" /> 
                        <telerik:RadSliderItem runat="server" Text="$25" Value="25" /> 
                        <telerik:RadSliderItem runat="server" Text="$50" Value="50" /> 
                        <telerik:RadSliderItem runat="server" Text="$75" Value="75" /> 
                        <telerik:RadSliderItem runat="server" Text="$100" Value="100" /> 
                        <telerik:RadSliderItem runat="server" Text="$125" Value="125" /> 
                        <telerik:RadSliderItem runat="server" Text="$150" Value="150" /> 
                        <telerik:RadSliderItem runat="server" Text="$200" Value="200" /> 
                        <telerik:RadSliderItem runat="server" Text="$250" Value="250" /> 
                        <telerik:RadSliderItem runat="server" Text="$300" Value="300" /> 
                        <telerik:RadSliderItem runat="server" Text="$500" Value="500" /> 
                        <telerik:RadSliderItem runat="server" Text="$1000" Value="1000" /> 
                        <telerik:RadSliderItem runat="server" Text="$1500" Value="1500" /> 
                        <telerik:RadSliderItem runat="server" Text="$1000" Value="1000" /> 
                        <telerik:RadSliderItem runat="server" Text="$2000" Value="2000" /> 
                        <telerik:RadSliderItem runat="server" Text="$3000" Value="3000" /> 
                        <telerik:RadSliderItem runat="server" Text="$4000" Value="4000" /> 
                        <telerik:RadSliderItem runat="server" Text="$5000" Value="5000" /> 
                    </Items> 
                </telerik:RadSlider> 
  2. Tsvetie
    Admin
    Tsvetie avatar
    1517 posts

    Posted 12 Aug 2009 Link to this post

    Hi Kansa,
    I suppose you would like to find the value of the selected item in the RadSlider, not the selected value of the slider itself. You can do this the following way:
    protected void RadSliderPrice_ValueChanged(object sender, EventArgs e) 
        RadSliderItem selectedItem = RadSliderPrice.Items[RadSliderPrice.Value]; 
        lblValue.Text = selectedItem.Value

    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. Aron
    Aron avatar
    80 posts
    Member since:
    Dec 2005

    Posted 12 Aug 2009 Link to this post

    Hi,
    I'm getting error:

    Index was out of range. Must be non-negative and less than the size of the collection.


    Please let me know what I should change, as this is a bit complicated for me.
    aspx

      <telerik:RadSlider AutoPostBack="true" ID="RadSliderQuant" runat="server" MinimumValue="20"  
                    MaximumValue="2000" onvaluechanged="RadSliderQuant_ValueChanged" AnimationDuration="400" CssClass="ItemsSlider" 
                    Width="650"  Height="35px" LargeChange="100" SmallChange="20" Orientation="Horizontal" TrackPosition="BottomRight" Value="100" 
                                        ItemType="Tick" > 
                </telerik:RadSlider> 

    cb

    protected void Page_Load(object sender, EventArgs e) 
        { 
            if (!Page.IsPostBack) 
                UpdateTotals(); 
        } 
        protected void RadSliderQuant_ValueChanged(object sender, EventArgs e) 
        { 
            UpdateTotals(); 
     
        } 
        protected void RadSliderPrice_ValueChanged(object sender, EventArgs e) 
        { 
            UpdateTotals(); 
        } 
     
        public void UpdateTotals() 
        { 
            RadSliderItem selectedItem = RadSliderPrice.Items[RadSliderPrice.Value]; 
     
            int price = Convert.ToInt32(selectedItem.Value); 
            int total = (RadSliderQuant.Value * price); 
            total = total * 12; 
            lt2.Text = string.Format("{0:C}", total * 0.2); 
            lt5.Text = string.Format("{0:C}", total * 0.05); 
            lt10.Text = string.Format("{0:C}", total * 0.1); 
            lt15.Text = string.Format("{0:C}", total * 0.15); 
            lt20.Text = string.Format("{0:C}", total * 0.2); 
     
            lbMath.Text = string.Format("{0} tickets per month is {1} per year. At {2:C} per ticket that is {3:C} gross venue.", RadSliderQuant.Value, (RadSliderQuant.Value * 12), price, price * (RadSliderQuant.Value * 12)); 
     
     
        } 
  5. Tsvetie
    Admin
    Tsvetie avatar
    1517 posts

    Posted 13 Aug 2009 Link to this post

    Hi Kansa,
    The RadSlider control has items in its Items collection, only in case you have set ItemType=Item and you have added items in its Items collection. You get the exception, because your slider has no Items:
    <telerik:RadSlider AutoPostBack="true" ID="RadSliderQuant" runat="server" MinimumValue="20"   
                    MaximumValue="2000" onvaluechanged="RadSliderQuant_ValueChanged" AnimationDuration="400" CssClass="ItemsSlider"  
                    Width="650"  Height="35px" LargeChange="100" SmallChange="20" Orientation="Horizontal" TrackPosition="BottomRight" Value="100"  
                                        ItemType="Tick" >  
    </telerik:RadSlider>  

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