Click here to Skip to main content
15,923,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am trying to filter the products on the base of price...

i have a link control on one page.. and i am redirctring the page to ProductCatalog.aspx to show the products in the grid

C#
<td align="center">
                               <asp:LinkButton ID="LinkButton4" PostBackUrl='<%# "~/ProductCatalog.aspx?PriceID="+Eval("UnitCost") %>' runat="server"><5000</asp:LinkButton>
                           </td>


on Products.Aspx page

C#
string query = "Select * from Products where '"+int.TryParse(Request.QueryString["PriceID"]<5000)+"'";


i am getting the error

C#
Error 1	Operator '<' cannot be applied to operands of type 'string' and 'int'	



IMproved
On Product Catalog.aspx page

C#
private void LoadGridView() // just calling it on page load
   {

       string query = "Select * from Products where UnitCost= " + Request.QueryString["ID"] + "<5000"; ;
       //DataSet ds = new DataSet();
       DataSet ds=obj.fillgrid(query);
       GridView1.DataSource = ds.Tables[0];
       GridView1.DataBind(); ;
       //conn.Close();
   }


and on my master page i embedd

ASP.NET
<table class="style1" width="20%">
            <tr>
                <td bgcolor="#666" align="center" class="style2" >
                    Search Products By Price Range</td>
                        </tr>
                        <tr bgcolor="#F7F7DE" >
                            <td align="center">
                                <asp:LinkButton ID="LinkButton4" PostBackUrl='<%# "~/ProductCatalog.aspx?ID="+Eval("UnitCost") %>' runat="server"><5000</asp:LinkButton>
                            </td>
                        </tr>
                        <tr bgcolor="#F7F7DE">
                            <td align="center">
                                <asp:LinkButton ID="LinkButton5" runat="server">>=5000 and <=10000</asp:LinkButton>
                            </td>
                        </tr>
                        <tr bgcolor="#F7F7DE">
                            <td align="center">
                                <asp:LinkButton ID="LinkButton6" runat="server">>=10000 and <=20000</asp:LinkButton>
                            </td>
                        </tr >
                        <tr bgcolor="#F7F7DE">
                            <td align="center">
                                <asp:LinkButton ID="LinkButton7" runat="server">>20000</asp:LinkButton>
                            </td>
                        </tr>
                    </table>
Posted
Updated 24-Dec-11 6:45am
v2

1 solution

C#
string query = "Select * from Products where " + Request.QueryString["PriceID"].ToString() + "<5000";

Use parametrized query
Or you can use filter in your DataSet or DataTable

EDIT

Actually whats the value of Eval("UnitCost")? Because the field name missing in your query(above code). You code should like below.
C#
string query = "Select * from Products where PriceID<5000";
Here you must send the value 5000 dynamically. Correct me if anything wrong

EDIT2

So you want to select products by range?
Your code should be like(There should be two columns in where condition ProductId & UnitCost)
C#
string query = "Select * from Products where ProductID= '" + Request.QueryString["ID"].ToString() + "' AND UnitCost < 5000";

BTW again I suggest you to use parametrized query.
 
Share this answer
 
v5
Comments
[no name] 24-Dec-11 11:33am    
I think the main pb is the silly and useless “int.TryParse(...)“Regards.
thatraja 24-Dec-11 11:44am    
Yes, BTW why did you delete your answer?
[no name] 24-Dec-11 11:48am    
Because maybe not appreciated because of a low point member answer;) Not a problem. Regards.
thatraja 24-Dec-11 11:59am    
Oh no, it doesn't matter. OP need answers, that's all. 2 years ago I was also a low point member. OK don't do that again. I'll restore your answer.
[no name] 24-Dec-11 12:01pm    
I deleted all my "useless" answers/comments until now, in the meaning to keep the forum clean :)
You have to know I'm a noob here.
Regards

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