Wednesday, March 21, 2012

populate value in dropdown

Hi, I have an update form which contains the selected employee information. I was able to use DataReader to retrieve the data from the database. I want to place the department value in the dropdown which contains other department values so user can change the dept value and save the information. How can I display my department value in the dropdown? I was able to populate the dropdown without any problem except the department value wasn't highlighted. It is like a person originally worked at Marketing department and is going to switch to IT.

Thanks in advance.

<asp:DropDownListID="DDDept"runat="server"AutoPostBack="True" DataSourceID="ObjectDataSource1"DataTextField="DeptName"DataValueField="DeptID"Style="z-index: 112; left: 372px;position: absolute; top: 415px"Width="159px"></asp:DropDownList>

SO you have your datasource all set up and the drop down list displays the departments correctly. However you want the users current department to be selected..

use the SelectedValue Property of the drop down list and set it to whatever key field in the users table that has the department id in it.

<asp:DropDownList SelectedValue='<# Bind("DepartmentIdFieldFromUsersTable") %>' .../>

should do it.

hth,

mcm


Hi, Thank you so much for the help!! I can see the department correctly now !!

0 comments:

Post a Comment