Click to See Complete Forum and Search --> : Updating textbox with dropdownlist selection


poq8
July 13th, 2009, 10:57 AM
Hi,

I'm trying to make a form where once the user selects an item from the drop down list, the textbox will automatically be populated with the user's selection.
I have two databases. One is for the department ID/name. The other is where the user's choices get saved (obviously, there are other fields for the user to fill out).
The dropdownlist gets its options from the first department ID/name database and when it is saved into the new database, it saves under the department ID (an int).

What I am trying to do is have it so that the user doesn't have to fill out the department name textbox. I want to make this textbox enabled="false", and once the dropdownlist index is changed, for the textbox to be populated with whatever ID was chosen.

I just can't figure out how to have the textbox and the dropdownlist connected and binding the textbox text to 'department'.

Here is my code:


<asp:TemplateField HeaderText="phbkdepartment_id" SortExpression="phbkdepartment_id">
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList3" runat="server" DataSourceID="dsDepartment" DataTextField="department_name"
DataValueField="department_id" Enabled="True" SelectedValue='<%# Bind("phbkdepartment_id") %>' >
</asp:DropDownList>
</InsertItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="department" SortExpression="department">
<InsertItemTemplate>
<asp:TextBox ID="txt511" runat="server" Width="100px" Text='<%# Bind("department") %>' />
</InsertItemTemplate>
</asp:TemplateField>