1

I have a set of categories that a user can choose from. Each category has a different set of properties that a user may want to filter on.

The items in each category are displayed in a grid view. Each category has its own web page for the grid view.

When the grid view is displayed I would like a side bar to display properties that pertain to the category. The user should be able to select a property to filter. And filter by min/max values on the property.

I'm trying to determine what controls should go in the sidebar and also how to dynamically populate the set of controls (assuming each one is a distinct property filter).

For example looking at Amazon books the sidebar has a dynamically generated list of filters that pertains to the category of books.

Other nice features would be:

  • Change the list of properties so that only properties/filters that will produce a result will be displayed.

  • Have each property/filter show the number of results that will be displayed if selected.

4

2 回答 2

3

I don't really know how you're going to load the gridview, but this is how I was able to do something similar.

Let's say you're getting your data to the GridView via SQL query:

select property1, property2, property3, ...., from categoryA

Whatever is on the side view should factor into your SQL query somehow, each of them with auto post back.

<asp:TextBox runat="server" AutoPostBack="true" ID="Property1" /> 

So when it posts back to the server, in your page load method:

protected void Page_Load(object sender, EventArgs e) 
{
    if(IsPostBack)
    { 
        UpdateCategoryQuery();
    }
}

And on your UpdateCategoryQuery() method:

private void UpdateCategoryQuery()
{
    if(Property1.Text != "") 
    {
        string sql = "where property1 = '" + Property1.Text + "'";
    }
    //... and go on down the list.   
}  

Finally, you will want to read this query and bind the data to the GridView using .DataSource and .DataBind();

It's an extremely simple example, but I didn't really know exactly what you were looking for, so I hope this helps you along.

Edit: The query here can get fairly complicated depending on how many properties you have to filter the data, so you may have to spend some time building it out to make sure it runs correctly.

于 2012-03-16T20:24:15.813 回答
0

I'm new to ASP.NET so I'm stuck finding the controls to accomplish this.

There aren't any controls out of the box, that accomplish this. You have to build your own.

This might not the way you envision, but hopefully is an idea that you can extrapolate:

Since you know the type of objects you are binding to the gridview, create a dropdown box with the list of properties the user can filter on. Next to the drop down, put a min and a max text field so that the user can type in whatever value he needs in those fields. Something like this:

<asp:dropdownlist id="properties" runat="server">
 <ListItem Text="Color" Value="Color" />
 <ListItem Text="Size"  Value="Size"/>
 <ListItem Text="Price" Value="Price"/>
</asp:dropdownlist>
<asp:Textbox id="min" runat="server" />
<asp:Textbox id="max" runat="server" />
<asp:Button id="btnFilter" Click="Filter" Text="Filter" />

protected void Filter(object sender, EventArgs e)
{
   string minVal = min.Text;
   string maxVal = max.Text;
   string filterProperty = properties.SelectedValue;

   //Now filter your data using the property name and the min and max values
   //you can use Linq to do this quickly. 
   //If binding to a DataTable, use DataTable.Select method and rebind again

}
于 2012-03-16T20:27:07.930 回答