Forum Moderators: open

Message Too Old, No Replies

ASP:DropDownList

Question about binding

         

flaboy

5:28 pm on Jul 1, 2005 (gmt 0)

10+ Year Member



I have two tables Employees, and Titles. I am using an Inner Join to create a dataset that returns a field value, amongst others, of title_name (i.e. CEO). I've written an update page in VB.net that dynamically populates a drop downlist with that dataset and that contains all available titles. No problems so far, but here's the catch. When choosing to update a record in the admin section, the drop down defaults to the first value in the title_name field (i.e. admin). I am trying to have the control default to the value associated with that particular employee, while still having all other options avaiable. Currently, if taking no action, the update always defaults to the first value- 'admin' and consequently updates the field with that value on submission. Thanks for any help.

Here's the control code:

[2]<asp:DropDownList 
DataSource="<%# dsTitles.DefaultView %>"
DataTextField="title_name"
DataValueField="emp_id_title"
ID="emp_id_title"
runat="server"
class="inputTxtbox"
Width="200">
</asp:DropDownList>[/2]

Here's the database code:

[2]<MM:DataSet 
id="dsTitles"
runat="Server"
IsStoredProcedure="false"
ConnectionString='<%# System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_connEmpdir") %>'
DatabaseType='<%# System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_DATABASETYPE_connEmpdir") %>'
CommandText='<%# "SELECT * FROM dbo.titles INNER JOIN employee ON title_id = emp_id_title ORDER BY title_name ASC" %>'
Debug="true"
></MM:DataSet>[/2]

TheNige

8:02 pm on Jul 1, 2005 (gmt 0)

10+ Year Member



You need to set the select item in the drop down list when you make the edit.

flaboy

12:24 pm on Jul 7, 2005 (gmt 0)

10+ Year Member



Should I do this through SQL, or is this a control attribute? I have tried selecting through SQL, but the problem that arises is that none of the other list options (i.e. titles) are available, only the title associated with the employee is populated. I need to have all titles available in the dropdown, while at the same time having the list default to the title associated with that employee....

TheNige

12:24 am on Jul 8, 2005 (gmt 0)

10+ Year Member



Load all of the options again and then search the dropdown for the one that needs to be selected and the set it to be selected.