数据 Web 控件显示值与存储过程的插入 ID(外键)

发布于 2024-12-05 14:01:48 字数 723 浏览 0 评论 0原文

我有一系列由 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一人独醉 2024-12-12 14:01:48

此外,最好使用单个查询和 SqlDataSource
填充所有下拉菜单。目前我正在使用一个单独的
为我拥有的 13 个用户类别中的每一个类别选择“select”语句。

不幸的是,您必须使用单独的数据源,因为如果您使用 SQLDataSource,则不支持此操作。

为了使用用户的 ID,请将 DataValueField 设置为 ID(假设列名称是 ID,如您所指示)

。用户,将 DataTextField 设置为 Name(假设列名称为 Name,如您所指示)

因此,DropDownList 应如下所示:

<asp:dropdownList id="your_id" DataTextField="Name" 
DataSourceID="YourSqlDataSourceID" DataValueField="ID" runat="server" />

链接 MSDN 文档。

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.

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 to ID (assuming that the column name is ID, as you indicated)

In order to display the Name of the user, set the DataTextField to Name (assuming that the column name is Name, as you indicated)

Therefore, the DropDownList should look like this:

<asp:dropdownList id="your_id" DataTextField="Name" 
DataSourceID="YourSqlDataSourceID" DataValueField="ID" runat="server" />

Linking MSDN Documentation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文