Home / Community & Support / Knowledge Base / RadControls for ASP.NET and ASP.NET AJAX / Slider / How to create a RadSliderItem for each record in a DataTable

How to create a RadSliderItem for each record in a DataTable

Article Info

Rating: 4

Article information

Article relates to

 RadSlider for ASP.NET AJAX

Created by

 Tsvetelina, Telerik

Last modified

 March 17, 2009

Last modified by

 Tsvetelina, Telerik

HOW-TO
Create a RadSliderItem for each record in a DataTable.

DESCRIPTION
The RadSlider control does not support DataBinding out of the box. However, there are a couple of scenarios when you would want to display the data from a DataTable using a RadSlider with items.

SOLUTION
First, you have to define a RadSlider that would display items. In order to do this, you only have to set the ItemType property of the control to "Item". Have a look at the sample code fragment below:
<telerik:RadSlider ID="RadSlider1" runat="server"  
    ItemType="Item" 
    Width="500px" 
    Height="50px" 
    TrackPosition="BottomRight"
</telerik:RadSlider> 

Now, In order to create a RadSliderItem in the RadSlider for each record in your DataTable, you have to loop trough the records of that DataTable, create an item using the information in the current row and add this item to the Items collection of the RadSlider.

C#:
// Create the RadSliderItems, based on the records in the DataTable 
foreach (DataRow row in dt.Rows) 
    RadSliderItem item = new RadSliderItem(row["ItemText"].ToString(), row["ItemValue"].ToString()); 
    RadSlider1.Items.Add(item); 

VB:
' Create the RadSliderItems, based on the records in the DataTable 
Dim row As DataRow 
For Each row In dt.Rows 
    Dim item As RadSliderItem = New RadSliderItem(row("ItemText").ToString(), row("ItemValue").ToString()) 
    RadSlider1.Items.Add(item) 
Next 

Comments

If you'd like to comment on this KB article, please, send us a Support Ticket.
Thank you!

Please Sign In to rate this article.