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

DataBind from Code-Behind

2 Answers 208 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Charles
Top achievements
Rank 1
Charles asked on 27 Mar 2012, 03:12 PM

I am replacing a standard listbox control with a RADLISTBOX control and thought it would be pretty seamless to switch out, but I am not having any luck with populating the RADLISTBOX. Can someone please tell me what I am doing wrong? I am not doing anything spectacular, just a simple databind with datareader.

Here is my code aspx.vb

Dim item As New RadListBoxItem()
           
        While reader4.Read
            item.Value = reader4("DescriptionLong")
            ConditionList.Items.Add(item)

Here is my aspx. code

<telerik:RadListBox ID="ConditionList" Width="160px" runat="server"
   Skin="Office2010Blue">
                     
</telerik:RadListBox>

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 28 Mar 2012, 06:39 AM
Hello Charles,

RadListBox can be bound to a DataTable, DataSet and a DataView. Following is a sample code which create and fill the DataTable object, then bind it to the RadListBox.

VB:
Protected Sub Page_Load(sender As Object, e As EventArgs)
    Dim str As [String] = System.Configuration.ConfigurationManager.ConnectionStrings("NorthwindConnectionString").ConnectionString
    Dim con As New SqlConnection(str)
    Dim command As [String] = "SELECT EmployeeID, FirstName FROM Employees"
    Dim ad As New SqlDataAdapter(command, con)
    Dim dt As New DataTable()
    ad.Fill(dt)
    ConditionList.DataTextField = "FirstName"
    ConditionList.DataValueField = "EmployeeID"
    ConditionList.DataSource = dt
    ConditionList.DataBind()
End Sub

For more information please take a look into the following documentation.
http://www.telerik.com/help/aspnet-ajax/listbox-data-binding-overview.html.

Thanks,
Princy.
0
Charles
Top achievements
Rank 1
answered on 28 Mar 2012, 07:33 PM
Princy,

Thank you! that is exactly what I needed. Works like a champ!!

Tags
ListBox
Asked by
Charles
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Charles
Top achievements
Rank 1
Share this question
or