Click here to Skip to main content
15,906,626 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I have a small problem.

I have 2 listboxes (ListBox1 & ListBox2)
In ListBox I have added items from DB (table -> teachers -> Name,ForeName, teachersID).
The table is related to table-Test (testID, teachersID, testName)

add items to ListBox1
///some code here
foreach (var i in teachers)
{
  lLstBox1.Items.Add(string.Format("{0} \t{1}", i.foreName, i.name));
}


everything works good, until these codelines.

So I added to ListBox1
ListBox1_SelectedIndexChanged

How I can get selected teacherID, if in ListBox1 is only Name & Forename?
I need get teachersID to fill ListBox2 items, where TeachersID is a variable.

private void listBoxSkolotaji_SelectedIndexChanged(object sender, EventArgs e)
{
 //some query.
 foreach(//some code here)
 {
   ListBox2.Items.add(//some code here)
 }


I hope you get the problem, that I need to get solved! :)
Thanks
Posted
Updated 22-Nov-10 19:59pm
v2

1 solution

Hi
Please following

C#
///some code here
foreach (var i in teachers)
{
  lLstBox1.Items.Add(new ListItem(string.Format("{0} \t{1}", i.foreName, i.name),i.teachersID));
}



Please do let me know, if you have any doubt.

Please provide "Vote":thumbsup: if this would be helpful, and make "Accept Answer" if this would be correct answer.:rose:

Thanks,
Imdadhusen
 
Share this answer
 
Comments
valza 23-Nov-10 2:23am    
hmmm... what do you thought about "new ListItem"?
what it is?

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