i have a list collection and this contains items from database. And i want to show these items in a list box. But how could i bound this list to my listbox control..
pls help me..
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Vishal GilbileRank #268 · 9.4K reputationPosted Apr 9, 2013, 12:09 AM EDT
What I got from your question is that you have a list and you want to bind this list to your listbox.
Following is the way. Let's say the List name is list.
listBox1.DataSource=list;
listBox1..DataValueField =listBox1.DataTextField="ColumnName";
listBox1.DataBind();
Hope that solves your problem.
With Regards,
Vishal Gilbile
Satyapriya NayakRank #47 · 31.5K reputationPosted Apr 8, 2013, 11:24 PM EDT
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
Default.aspx.vb code
Imports System.Data
Imports System.Data.SqlClient
Partial Class _Default
Inherits System.Web.UI.Page
Dim strConnString As String = System.Configuration.ConfigurationManager.ConnectionStrings.Item("ConnectionString").ToString()
Dim con As New SqlConnection(strConnString)
Dim str As String
Dim com As SqlCommand
Dim sqlda As SqlDataAdapter
Dim ds As DataSet
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
con.Open()
str = "select * from employee"
com = New SqlCommand(str, con)
sqlda = New SqlDataAdapter(com)
ds = New DataSet
sqlda.Fill(ds, "employee")
ListBox1.DataValueField = "empid"
ListBox1.DataTextField = "empname"
ListBox1.DataSource = ds
ListBox1.DataMember = "employee"
ListBox1.DataBind()
con.Close()
End Sub
End Class
santosh parida34 reputationPosted Apr 8, 2013, 11:33 PM EDT
santosh parida34 reputationPosted Apr 8, 2013, 11:34 PM EDT
santosh parida34 reputationPosted Apr 9, 2013, 12:32 AM EDT