Click here to Skip to main content
15,891,812 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
Hi,

I am trying to bind a listbox to a dataset. But my listbox does not have the
.DisplayMember
and
.ValueMember
property. Do I need to include some DLL? or is my version of Visual studio does not support it?

Thanks!

Franco Cipriano
Posted
Comments
[no name] 16-Jul-12 17:27pm    
I *think* you are looking for the DataSource property.
Abdul Quader Mamun 17-Jul-12 0:24am    
use DataTextField ,DataValueField , and DataSource Property

1 solution

Hi Franco, ListBox does not contain any property called DisplayMember or ValueMember. Instead of this you need to use DataTextField and DataValueField property of List Box:-
C#
myListBox.DataSource = ds;
myListBox.DataTextField = "Emp_Name";
myListBox.DataValueField = "Emp_Id";
myListBox.DataBind();


Hope you got it.
Good luck.
 
Share this answer
 
v2
Comments
Franco Cipriano 17-Jul-12 10:36am    
Thanks for the clarification..just a follow up question on this..now that I binded the data to the listbox, it now shows the Emp_name on the list box. Now, when I select the Emp_name and press the button Select, I want to store the Emp_id in a variable..but what it gives me is still the Emp_name and not the Emp_id..i have this in code:

varID = myListbox.SelectedItem.Text;
Franco Cipriano 17-Jul-12 10:43am    
...i think i got the answer :)

varID = myListbox.SelectedItem.Value.ToString();

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900