Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Populating a combobox with a list objetct
Message
From
05/08/2010 14:43:12
 
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 4.0
OS:
Windows XP SP2
Network:
Windows 2008 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01475380
Message ID:
01475399
Views:
31
>i have a combobox that's populated using a foreach loop through a list object. There are three items from the database that get added to the list: id, paycode, description. The only way I know how to do it is by creating a string. But what I need is to separate the id into it's own column, so we can use it to do a lookup through a stored procedure. Can anyone tell me how this is done?
>
>Thanks!

Can you use an object for the ListBox binding ? eg:
   public class Thing
    {
        public int Id { get; set; }
        public int PayCode { get; set; }
        public string Description { get; set; }
    }
then:
List<Thing>  things = new List<Thing>();
            things.Add(new Thing{Id=1,PayCode=2,Description="One Thing"});
            things.Add(new Thing { Id = 2, PayCode = 3, Description = "Another Thing" });
            listBox1.DataSource = things;
            listBox1.DisplayMember = "Description";
When you need to see which item is selected:
Thing  thing = (Thing) listBox1.SelectedItem;
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform