我希望使用带有复选框列表作为控制参数的查询从数据库中检索数据行。问题是复选框列表上的多个选定值仅返回一个值,如此处所示...
<asp:CheckBoxList ID="CheckBoxList1" runat="server" RepeatDirection="Horizontal" DataSourceID="SqlDataSource1" DataTextField="Fruit" DataValueField="Fruit" ></asp:CheckBoxList>
<asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString='<%$ ConnectionStrings:f-StopConnectionString %>' SelectCommand="SELECT [Fruit] FROM [Table_1]"></asp:SqlDataSource>
<br />
<asp:Button ID="Button1" runat="server" Text="Select" OnClick="Button1_Click" />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource4">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID"></asp:BoundField>
<asp:BoundField DataField="Fruit" HeaderText="Fruit" SortExpression="Fruit"></asp:BoundField>
</Columns>
</asp:GridView>
<asp:SqlDataSource runat="server" ID="SqlDataSource4" ConnectionString='<%$ ConnectionStrings:f-StopConnectionString %>'
SelectCommand="SELECT * FROM [Table_1] WHERE ([Fruit] LIKE '%' + @Fruit + '%')">
<SelectParameters>
<asp:ControlParameter ControlID="CheckBoxList1" PropertyName="SelectedValue" Name="Fruit" Type="String"></asp:ControlParameter>
</SelectParameters>
</asp:SqlDataSource>
有没有办法传递多个选择,以便查询读取:
(WHERE [Fruit] LIKE '%'Apples'%') OR (WHERE [Fruit] LIKE '%'Oranges'%')
任何帮助都将不胜感激。