开发者

Data Web Controls Display Value vs Insert ID (foreign key) for Stored Procedures

开发者 https://www.devze.com 2023-04-06 10:07 出处:网络
I\'ve got a series of comboboxes made from ASP.NET开发者_StackOverflow社区 DropDownLists (populated from a select command from an SqlDataSource by DataSourceID), and <input> element, and the jQuery

I've got a series of comboboxes made from ASP.NET开发者_StackOverflow社区 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消