Reputation: 41
How do I display a table value in a listbox control? From this code I got the ProjectCode value from the TeamMember_table:
SqlDataAdapter adp = new SqlDataAdapter("select ProjectCode from TeamMember_table where EmpId = '" + eid + "'", conn);
I want to display this ProjectCode value in a listBox.
Platform: Visual Studio 2008, ASP.NET with C#.
Upvotes: 0
Views: 6413
Reputation: 3455
Using the ASP.NET ListBox control you can do it by assigning the DataSource property:
ListBox1.DataSource = YourDataSource;
ListBox1.DataTextField = "projectCode";
ListBox1.DataBind();
Where "YourDataSource" can be a DataTable filled with data from your SqlDataAdapter.
You can also add every item manually:
ListItem item = new ListItem();
item.Text="sometext";
item.Value="somevalue";
ListBox1.Items.Add(item);
You can read more about data binding and the ASP.NET ListBox control here.
Upvotes: 2