数据 Web 控件显示值与存储过程的插入 ID(外键)
我有一系列由 ASP.NET DropDownLists 制成的组合框(通过 DataSourceID 从 SqlDataSource 的选择命令填充),以及 元素和 jQueryUI 自动完成插件。不过你可以忽略后两者。
每个 DropDownList 控件代表一个特定的“用户”类别,并根据该类别的 Users
表动态填充。这是数据库结构:
Users (ID, Name) -- I use a join to display the Name, but I wish to USE the ID.
Team (ID, Member1, Member2, Member3) --each member is a foreign key to the
--"Users" table and used to populate the
--DropDownLists respectively.
问题:我需要知道如何在控件中显示Name
字段,但实际上使用所选的ID
值作为我的存储过程的输入。
- 此外,最好使用单个查询和 SqlDataSource 来填充所有下拉列表。目前,我为 13 个用户类别中的每一个使用单独的“选择”语句。
I've got a series of comboboxes made from ASP.NET DropDownLists (populated from a select command from an SqlDataSource by DataSourceID), and <input> element, and the jQueryUI autocomplete plugin. You can ignore the latter two though.
Each of the DropDownList controls represents a particular "User" category and is dynamically populated based on Users
table for that category. Here's the database structure:
Users (ID, Name) -- I use a join to display the Name, but I wish to USE the ID.
Team (ID, Member1, Member2, Member3) --each member is a foreign key to the
--"Users" table and used to populate the
--DropDownLists respectively.
QUESTION: I need to know how to display the Name
field in the control, but actually use the ID
of the selected value as the input to my stored procedure.
- additionally, it would be nice to use a single query and SqlDataSource to populate all the drop-downs. Currently I'm using a separate 'select' statement for each of 13 user categories I have.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,您必须使用单独的数据源,因为如果您使用 SQLDataSource,则不支持此操作。
为了使用用户的 ID,请将
DataValueField
设置为ID
(假设列名称是 ID,如您所指示)。用户,将
DataTextField
设置为Name
(假设列名称为 Name,如您所指示)因此,DropDownList 应如下所示:
链接 MSDN 文档。
Unfortunately, you have to use separate datasources as there's no support for this if you use SQLDataSource.
In order to Use the ID of the user, set the
DataValueField
toID
(assuming that the column name is ID, as you indicated)In order to display the Name of the user, set the
DataTextField
toName
(assuming that the column name is Name, as you indicated)Therefore, the DropDownList should look like this:
Linking MSDN Documentation.