我正在尝试将TeacherForename + TeacherSurname的字段连接到我的下拉列表中,以便让用户更清楚地选择了哪位教师。
然而,TeacherForename + TeacherSurname将保留TeacherID的值。
<div class="fields">
<p>
<asp:Label ID="TeacherIdentification" runat="server" Font-Bold="True"
Width="150px">Teacher ID:</asp:Label>
<asp:DropDownList ID="DropDownList2" runat="server"
DataSourceID="SqlDataSource2" DataTextField="TeacherForename"
DataValueField="TeacherID" Height="29px" Width="155px"
CssClass="Dropdownlist">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
SelectCommand="SELECT Class.TeacherID, Teacher.TeacherForename, Teacher.TeacherSurname FROM (Class INNER JOIN Teacher ON Class.TeacherID = Teacher.TeacherID)">
</asp:SqlDataSource>
</p>
</div>
我自己试图这样做,但是我无法正确选择命令并且它不会显示在我的下拉列表中,是否有人能指出我正确的方向?
答案 0 :(得分:0)
<div class="fields">
<p>
<asp:Label ID="TeacherIdentification" runat="server" Font-Bold="True"
Width="150px">Teacher ID:</asp:Label>
<asp:DropDownList ID="DropDownList2" runat="server"
DataSourceID="SqlDataSource2" DataTextField="TeacherForename"
DataValueField="TeacherID" Height="29px" Width="155px"
CssClass="Dropdownlist">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
SelectCommand="SELECT Class.TeacherID, (Teacher.TeacherForename + '' + Teacher.TeacherSurname) as TeacherFullName FROM Class INNER JOIN Teacher ON Class.TeacherID = Teacher.TeacherID ">
</asp:SqlDataSource>
</p>
</div>