我想按下拉列表值进行搜索。我在这个实例中使用ControlParameters,并希望通过用户选择的下拉列表进行搜索。是否可以使用ControlParameters?我把错误放在下面,但我得到的错误是
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
<p>Show all employees with the following title:</p>
<asp:SqlDataSource id="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:mySQLConnectionString%>"
SelectCommand="SELECT * FROM tblmovie"
FilterExpression="MovieID='{0}' or MovieName Like '%'{1}'%' and {2} Like '%'{3}'%'">
<FilterParameters>
<asp:ControlParameter Name="MovieID" ControlId="DropDownList1" PropertyName="SelectedValue"/>
<asp:ControlParameter Name="MovieName" ControlId="DropDownList2" PropertyName="SelectedValue"/>
<asp:ControlParameter Name="Search" ControlId="DropDownList3" PropertyName="SelectedValue"/>
<asp:ControlParameter Name="Search1" ControlId="txtSearch" PropertyName="text" Type="String"/>
</FilterParameters>
</asp:SqlDataSource>
<table style="width: 650px" border="0" cellpadding="0" cellspacing="1" >
<tr>
<td style="width: 150px;">
Movie ID
<asp:DropDownList id="DropDownList1" runat="server" AutoPostBack="True">
<asp:ListItem Value="888">Please Select...</asp:ListItem>
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
</asp:DropDownList>
</td>
<td style="width: 150px;">
Movie Name
<asp:DropDownList
id="DropDownList2"
runat="server"
AutoPostBack="True">
<asp:ListItem Value="999">Please Select...</asp:ListItem>
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
</asp:DropDownList>
</td>
<td style="width: 150px;">
Search
<asp:TextBox ID="txtSearch" runat="server" AutoPostBack="True" />
</td>
<td style="width: 150px;">
Where
<asp:DropDownList id="DropDownList3" runat="server" AutoPostBack="True">
<asp:ListItem>Please Select...</asp:ListItem>
<asp:ListItem>MovieName</asp:ListItem>
<asp:ListItem>MovieID</asp:ListItem>
<asp:ListItem>Oscars</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr><td colspan="4">
<p>
</p>
<p></p>
</td></tr>
<tr>
<td colspan="4">
<asp:GridView id="GridView1" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="False" Width="600px">
<columns>
<asp:BoundField HeaderText="Movie Name" DataField="MovieName" />
<asp:BoundField HeaderText="MovieID" DataField="MovieID" />
<asp:BoundField HeaderText="Release Date" DataField="ReleaseDate" />
<asp:BoundField HeaderText="Oscars" DataField="Oscars" />
</columns>
</asp:GridView>
</td>
</tr>
</table>
</form>
</body>
</html>
答案 0 :(得分:1)
FilterExpression="MovieID={0} or MovieName Like '%{1}%' or Oscars={2} Where {3} Like '% txtSearch.text %'">
对我来说很奇怪。
FilterExpression =“MovieID = {0}或MovieName赞'%{1}%'或奥斯卡= {2} 其中 {3}赞'%txtSearch.text%'”&gt; < / p>
我不认为“Where”这个词应该在那里?它应该是“AND”还是“OR”?
对我而言,似乎在过滤器表达式的开头有一个隐含的(你不必键入的)“WHERE”。