Filtering Grid in Visual Studio 2010 Using ListBox
I am building a database-driven web application in VS 2010 and I have a page that displays my data in a GridView. I would like to be able to filter the results according to "Type", the name of one of my columns.
I have added a ListBox whose entries are populated via an EntityDataSource from my database, and I have both AutoPostBack set and SelectionMode on Multiple. Then, my GridView uses the following code to populate:
<asp:EntityDataSource ID="EntityDataSource2" runat="server"
AutoGenerateWhereClause="True" ConnectionString="name=ABCCandidatesEntities"
DefaultContainerName="ABCCandidatesEntities" EnableFlattening="False"
EntitySetName="Candidates" EntityTypeFilter="Candidate" Where="">
<WhereParameters>
<asp:ControlParameter ControlID="ListBox1" Name="Type"
PropertyName="SelectedValue" />
</Whe开发者_如何学JAVAreParameters>
</asp:EntityDataSource>
While this works fine if only one item in the ListBox is selected, it does not work if multiple are -- it just treats it as a single selection. How can I get this to work?
On a site note, are there easier ways to set up filtering of a GridView?
Thank you!
If you look at the intellisence it shows that .SelectedValue
returns a string.
The .GetSelectedIndices()
is the only member that returns all selected values from what I can see, But because it is a method and not a property not sure how your suppose to bind to it.
From what I can tell this is a limitation of the listbox. To get the functionality your looking for you'll need to write some codebehind, and/or javascript to pull out the values for your query.
精彩评论