0 down vote favorite
share [g+] share [fb] share [tw]
I have a database table called Employees that has an ID number, First Name, Last Name, and SupervisorID for each employee. The SupervisorID stored for an employee equals the ID number of that employee's supervisor.
I want to have a DetailsView control that can edit these fields for an employee. The Supervisor field needs to be a dropdown that stores the SupervisorID as the value, and shows the supervisor's First Name and Last Name as it's text.
I've looked around a lot and was able to figure out how to create the dropdown to select and show SupervisorID's. Where I'm stuck is how do I change the code below to store the SupervisorID, but show the Supervisor's name as it's text?
Here's the code for the Supervisor dropdown within my DetailsList:
<asp:TemplateField HeaderText="Supervisor" SortExpression="SupervisorID">
<EditItemTemplate>
<aspropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource3" DataTextField="SupervisorID" DataValueField="SupervisorID" SelectedValue='<%# Bind("SupervisorID") %>'>
</aspropDownList>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:dbConnectionString %>" SelectCommand="SELECT [SupervisorID] FROM [Employees]"></asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate >
<asp:Label Runat="server" Text='<%# Bind("SupervisorID") %>' ID="Label1"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Any ideas for what I can change to accomplish my goal? Thanks for any help!
share [g+] share [fb] share [tw]
I have a database table called Employees that has an ID number, First Name, Last Name, and SupervisorID for each employee. The SupervisorID stored for an employee equals the ID number of that employee's supervisor.
I want to have a DetailsView control that can edit these fields for an employee. The Supervisor field needs to be a dropdown that stores the SupervisorID as the value, and shows the supervisor's First Name and Last Name as it's text.
I've looked around a lot and was able to figure out how to create the dropdown to select and show SupervisorID's. Where I'm stuck is how do I change the code below to store the SupervisorID, but show the Supervisor's name as it's text?
Here's the code for the Supervisor dropdown within my DetailsList:
<asp:TemplateField HeaderText="Supervisor" SortExpression="SupervisorID">
<EditItemTemplate>
<aspropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource3" DataTextField="SupervisorID" DataValueField="SupervisorID" SelectedValue='<%# Bind("SupervisorID") %>'>
</aspropDownList>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:dbConnectionString %>" SelectCommand="SELECT [SupervisorID] FROM [Employees]"></asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate >
<asp:Label Runat="server" Text='<%# Bind("SupervisorID") %>' ID="Label1"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Any ideas for what I can change to accomplish my goal? Thanks for any help!