ID插入而不是名称

问题描述:

我创建了一个下拉列表,当我单击保存按钮时,我想从数据库中填充该列表,我希望代码搜索表列中的数据,如果存在,请在列表中插入uniqueID而不是文本.


这可能吗.如果可以,我可以获取代码示例或指向类似内容的链接.

I created a dropdown list which populate from a database when I click the save button I would like for the code to search through the data in the table column and if exist insert uniqueID instead of the text in the dropdown list.


Is this possible. if so can I get and example of the code or a link to something similar.

我将假定您的平台为ASP.NET.请参阅以下内容:

ListItem [ ListItem.Text [ ^ ]
ListItem.Value [ ^ ]

您可以仅将文本设置为一件事,将值设置为另一件事.您将需要执行该操作.只需在构造数据库语句时使用值"成员即可.
I''ll assume your platform is ASP.NET. See the following:

ListItem[^]
ListItem.Text[^]
ListItem.Value[^]

You can just set the text to one thing and the value to another. You will need that to do what you''re trying to do. Just use the ''value'' member when constructing your database statement.


是的...很简单

参见此处 ADO .NET示例 [
yeah...it''s very easy

see here ADO .NET examples[^]


如果您的下拉列表与数据库绑定,那么您可以将value属性用作ID(即主键或唯一键),并将Text属性用于文本哪个显示.
if your dropdown list is bound with data base then u can use value property for ID which is primary key or unique key and Text property for text which display.