Hello Nick,
Thanks for your reply.
For your scenario, you can simply add some code in the
SqlDataSource.Filtering event, then construct a Filter expression string
and assign it to the SqlDataSource control. e.g.
========aspx page===========
<form id="form1" runat="server">
<div>
<asp:ListBox ID="lstSelected" runat="server"
SelectionMode="Multiple">
<asp:ListItem>name1</asp:ListItem>
<asp:ListItem>name2</asp:ListItem>
<asp:ListItem>name3</asp:ListItem>
<asp:ListItem>name4</asp:ListItem>
</asp:ListBox>
<asp:Button ID="btnSelect" runat="server" Text="Select Button"
OnClick="btnSelect_Click" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ASPNETTestDBConnectionString2 %>"
SelectCommand="SELECT [id], [name], [description] FROM
[RVTable]"
FilterExpression="name='name1'OR name='name2'"
OnFiltering="SqlDataSource1_Filtering"
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataKeyNames="id" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="id" HeaderText="id"
InsertVisible="False" ReadOnly="True"
SortExpression="id" />
<asp:BoundField DataField="name" HeaderText="name"
SortExpression="name" />
<asp:BoundField DataField="description"
HeaderText="description" SortExpression="description" />
</Columns>
</asp:GridView>
</div>
</form>
...............
=================================
=======code behind=====
protected void SqlDataSource1_Filtering(object sender,
SqlDataSourceFilteringEventArgs e)
{
string exp = string.Empty;
foreach (ListItem item in lstSelected.Items)
{
if (item.Selected)
{
if (exp != string.Empty)
{
exp += " OR ";
}
exp += "name='" + item.Value + "'";
}
}
if(exp != string.Empty)
SqlDataSource1.FilterExpression = exp;
}
protected void btnSelect_Click(object sender, EventArgs e)
{
GridView1.DataBind();
}
========================
Hope this helps.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.