Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
In my Default.aspx page I have 2 datalist, first one is populated with categories and second one is populated with colors, ( as item template for both of them im using hyperlink) and I have listview that shows products.

So i want to sort data using those two datalists.... when I select one of categories the listview is populated with that category in the same page for e.g : - Default.aspx?CategoryID=1
( which i have done that)... but when I want this category products to be also sorted by
colors now here is the problem ...!!! I dont know how to achieve that :\

I know that after selecting second datalist whith color, url should be something like this:

Default.aspx?CategoryID=1&Color=red
or
Default.aspx?CategoryID=1&ColorID=1

any idea ?!

HERE IS Code
XML
<div class="Div1" style="width: 150px; float: left;">
    <p>

        <asp:DataList ID="CateoriesDataList" runat="server">
            <HeaderTemplate>
                Categories
            </HeaderTemplate>
            <ItemTemplate>
                <asp:HyperLink ID="CategoryHyperLink" runat="server" Text='<%#Eval("CategoryName").ToString() %>'
                     NavigateUrl='<%#String.Format("Categories.aspx?Category=" + (Eval("CategoryID").ToString() + "&" +Request.QueryString.ToString())) %>'></asp:HyperLink>

            </ItemTemplate>
        </asp:DataList>
    </p>
    <p>
        <asp:DataList ID="ColorsDataList" runat="server">
            <HeaderTemplate>
                Colors
            </HeaderTemplate>
            <ItemTemplate>
                <asp:HyperLink ID="ColorLink" runat="server" Text='<%# Eval("Color").ToString() %>'
                        NavigateUrl='<%#String.Format("Categories.aspx?Category=" + (Eval("CategoryID").ToString() + "&" +Request.QueryString.ToString())) %>'></asp:HyperLink>
            </ItemTemplate>
        </asp:DataList>
    </p>
    </div>
    <div class="Div2" style="float: left; width: 300px;">
        <asp:DataList ID="ProductsDataList" runat="server">
            <HeaderTemplate>
                Products
            </HeaderTemplate>
            <ItemTemplate>
                <asp:Image ID="Image1" runat="server" Height="53px" Width="65px" />
                <asp:HyperLink ID="HyperLink3" runat="server">HyperLink</asp:HyperLink>
                <br />
            </ItemTemplate>
        </asp:DataList>
    </div>



So its something like when you baying shoes from Footlocker.com ... and then you doing some kind of sorting lake: Basketball shoes, price, brand, size... etc
so thats my issue

I like to select category then i like to sort selected data by color or price...and my Default.asx?CategoryID=1&colorID=1 not to show duplicated parameters when again I want to filter by categories exp: Default.asx?CategoryID=3&CategoryID=1&colorID=1

if someone have any idea or can lead me to another source which referes to this kind of issues, I will be very thankful...
I Appreciete your time truely
Posted
Updated 15-Mar-13 9:19am
v3
Comments
[no name] 4-Mar-13 21:19pm    
Maybe you should go ahead and post some code that demonstrates your problem.
VishwaKL 5-Mar-13 3:55am    
read your query stating Request.QueryString["Stringkey"] pass that to your method and display related data
Maho^^^ 15-Mar-13 14:59pm    
yes, Im doing that. Im passing QueryString to method and i get the result but im wondering how to filter retrieved data using second and third querystring...
vinodkumarnie 16-Mar-13 3:34am    
can you share your datasource used for ProductsDataList datalist...?
Maho^^^ 16-Mar-13 10:09am    
tnx for your time, here you go:

string categoryId = Request.QueryString["CategoryID"];
string colorId = Request.QueryString["ColorID"];

if (categoryId == null & colorId == null)
{
this.ProductsDataList.DataSource = GetAllProducts();
this.ProductsDataList.DataBind();
}
else if (CategoryId != null)
{
this.ProductsDataList.DataSource = GetProductsByCategory(categoryId);
this.AdvList.DataBind();
}
else if (colorId != null)
{
this.ProductsDataList.DataSource = GetProductsByColor(colorId);
this.ProductsDataList.DataBind();
}
else if (categoryId != null && color != null)
{
this.ProductsDataList.DataSource = GetProductsByCatAndColor(categoryId, colorId);
this.ProductsDataList.DataBind();
}
But this nothing got to do with QueryString Parameters and Url... Im trying to find a way how to deal with querystrings in Url...

1 solution

Hey if you using a data table to bind to the data list look here http://msdn.microsoft.com/en-us/library/system.data.datatable.compute.aspx this is a very handy function to filter and sort your data table based on your query string values before binding to the data list.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900