获取组合框所选值的ID [英] get the id of a combobox selected value

查看:79
本文介绍了获取组合框所选值的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好.
我有一个客户表和一个交易表.我使用两个组合框从客户那里获取特定交易.我使用第一个cobobox来显示所有客户,然后通过选择我想要的客户,我筛选了第二个组合框,该组合框显示了交易,以便从第一个组合框的所选用户那里获得我想要的交易.
在表中,每个客户都有自己的ID,每笔交易都有自己的ID.在交易ID旁边,我存储进行交易(进行过滤)的客户的ID.
我需要您的帮助来获取第二个组合框的所选事务的ID,并将其显示在标签或文本框中.
换句话说,我想立即从第二个组合框中选择交易,标签的值将更改并显示所选交易的ID.
我使用Visual Studio 2005和C#,它是Windows窗体项目,而不是ASP.NET btw.

提前感谢所有帮助人员.

Hi there.
I have a table of customers and a table of transactions. I use two comboboxes to get the specific transaction from a customer. I use the first cobobox to display all the customers and then by selecting the customer i want, i filter the 2nd combobox which displays the transactions to get the one i want from the selected user of the first combobox.
In the tables, each customer has its id and each transaction has its own id. Next to the transaction''s id i store the id of the customer who made the transaction(to make the filtering).
I want your help in getting the id of the selected transaction of the 2nd combobox and display it to a label or a textbox.
In other words i want the instant i choose the transaction from the 2nd combobox, the value of the label to change and display the id of the selected transaction.
I use visual studio 2005 and c# and it is a windows forms project NOT ASP.NET btw.

Thnx in advance for any help guys.

推荐答案

Jim,

为此,您必须将组合用文本和值绑定为
Jim,

For this what you have to do is, you have to bind the combo''s with text and value as
combo1.Item[1].text = "CustomerName";
combo1.Item[1].Value = "CustomerId"



或者您分配了任何数据源
然后这样写



or if you assign any datasource
then write like this

combo1.DisplayMember = "CustomerName"; //Column name
combo1.ValueMember = "CustomerID"; //Column name2




现在,如果要单击combo1.




Now if their is a click on combo1.

combo2.value=combo1.selectedvalue;



谢谢

SP



Thanks

SP


您需要在所有组合框列表项中存储所有数据,例如承载客户信息,ID的某种结构.该项目可以是任何类型的对象.当您需要此信息时,只需将项目转换为您要输入的内容.
唯一的问题是:如果您的组合框列表项不是字符串,则该项中将显示什么文本?问题是:无论方法ToString返回什么,因此您都需要在项目类型中覆盖System.Object.ToString.像这样的东西:

You need to store all data such as some structure carrying customer information, ID, whatever else in each combo box list item. The item can an object be of any type. When you need this information, you simply cast item to you type.

The only problem is: if your combo box list items are not strings, what text will be shown in the item? The question is: whatever the method ToString returns, so you will need to override System.Object.ToString in you item type. Something like that:

struct MyListItem {
   public override ToString() {
      return string.Format("{0}: {1}", this.name, this.id);
   }
   internal string Name { get { return this.name; } }
   internal int Id { get { return this.id; } }
   //...
   int id;
   string name;
   //...
}



—SA



—SA



希望您在交易表中有客户ID作为外键.
当您绑定第二个下拉列表时,获取数据并绑定
Hi,
Wish you have customer ID in transaction table as forign key.
when you bind the second dropdownlist take the data and bind
ValueMember 

作为交易ID和

as Tranaction ID and

DisplayMember 

作为交易名称.

那么您可以选择交易ID作为选择客户的方式
id.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview_events.aspx [ ^ ]

希望有帮助.

as Tranaction Name.

then you can select the transaction id as the way you have selected customer
id.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview_events.aspx[^]

hope this help.


这篇关于获取组合框所选值的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆