我一直在尝试在visual studio .net中填充下拉列表但是每当我尝试在查询中使用文本框时,我一直在使用visual studio中的select语句向导,并在尝试时给出错误在sql select命令中使用文本框,或者在测试查询时给出空字段。
<table class="auto-style1">
<tr>
<td class="auto-style1"></td>
<td class="auto-style2">
Select Class:</td>
<td class="auto-style1">
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1" DataTextField="ClassName" DataValueField="ClassName"></asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [ClassName] FROM [Classroom] WHERE ([TeacherUsername] = @TeacherUsername)">
<SelectParameters>
<asp:FormParameter FormField="TextBox1.Text" Name="TeacherUsername" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</td>
<td class="auto-style1">
<asp:TextBox ID="TextBox1" runat="server" OnTextChanged="TextBox1_TextChanged" Visible="False"></asp:TextBox>
<asp:Label ID="Label1" runat="server" Text="Label" Visible="False"></asp:Label>
</td>
</tr>
</table>
所以任何人都可以帮我把我的文本框包含在我的sql select查询中,谢谢!
答案 0 :(得分:0)
只需修改您的SelectCommand,删除TeacherUsername的where子句并为其添加过滤器:
SelectCommand="SELECT [ClassName] FROM [Classroom]" FilterExpression="TeacherUsername= '{0}'"