获取selectedItem客户ID表单列表框 [英] Get selectedItem customerID form Listbox
问题描述
我有一个小问题.
我有2个列表框(ListBox1& ListBox2)
在列表框中,我从数据库中添加了项目(表->教师->名称,ForeName,教师ID).
该表与表-Test(testID,教师ID,testName)有关
将项目添加到ListBox1
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));
}
一切正常,直到这些代码行.
所以我添加到ListBox1
ListBox1_SelectedIndexChanged
如果在ListBox1中只有Name& ;,则如何获取所选的TeacherID.姓?
我需要获取TeacherID来填充ListBox2项,其中TeachersID是一个变量.
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
推荐答案
嗨
请关注
Hi
Please following
///some code here
foreach (var i in teachers)
{
lLstBox1.Items.Add(new ListItem(string.Format("{0} \t{1}", i.foreName, i.name),i.teachersID));
}
如有任何疑问,请让我知道.
请提供"投票":thumbsup:如果有帮助,请提供"接受答案",如果这是正确的答案.:rose:
谢谢,
Imdadhusen
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
这篇关于获取selectedItem客户ID表单列表框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!