Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i am filtering the data on the bases of productscatalog.aspx page using this code


Product Catalog.aspx

ASP.NET
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ProductCatalog.aspx.cs" Inherits="ProductCatalog" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
    
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            onselectedindexchanged="GridView1_SelectedIndexChanged" Width="385px">
            <columns>
                <asp:TemplateField>
                    <itemtemplate>
                    
                        <table style="width: 100%">
                        <tr>
                            <td rowspan="4" valign="top" width="5%">
                                <asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("ProductImage") %>' /></td>
                            <td align="left">
                                <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("ProductID", "~/displayproduct.aspx?productid={0}") %>'
                                    Text='<%# Eval("ProductName") %>'></td>
                        </tr>
                        <tr>
                            <td align="left">
                                <asp:Label ID="Label3" runat="server" Text='<%# GetShortDescription(Eval("Description").ToString()) %>'></td>
                        </tr>
                        <tr>
                            <td align="left">
                                <asp:Label ID="Label5" runat="server" SkinID="FormLabel" Text="Price :">
                                <asp:Label ID="Label4" runat="server" Text='<%# Eval("UnitCost", "{0:C}") %>'></td>
                        </tr>
                        <tr>
                            <td align="right">
                                 </td>
                        </tr>
                    </table>
                    </itemtemplate>
                
            </columns>
        
    
    </div>
    </form>
</body>
</html>


product catalog.cs file is


C#
 SqlConnection conn = new SqlConnection("Data Source=FAROOQPC\\SQLEXPRESS; Initial Catalog=ecommerce; Integrated Security=True");
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            LoadGridView();

        }

    }
    private void LoadGridView()
    {
        //conn.Open();
        SqlDataAdapter da = new SqlDataAdapter("Select * from ESK_Products where CategoryID='"+Request.QueryString["CategoryID"]+"')", conn);
        DataSet ds = new DataSet();
        da.Fill(ds, "mydb");
        GridView1.DataSource = ds.Tables[0];
        GridView1.DataBind(); ;
        //conn.Close();
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected string GetShortDescription(string longdesc)
    {
        if (longdesc.Length <= 255)
        {
            return longdesc;
        }
        else
        {
            return longdesc.Substring(0, 255) + "...";
        }
    }
}



and i have the catgory page which has a linkbutton in datagrid vview passing the query string



ASP.NET
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            Width="124px">
            <columns>
                <asp:TemplateField>
                    <itemtemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" 
                            Text='<%# Eval("CategoryName") %>' PostBackUrl='<%#"~/ProductCatalog.aspx?ID="+Eval("CategoryID") %>'>
                    </itemtemplate>
                
            </columns>
            <emptydatatemplate>
                <asp:HyperLink ID="HyperLink1" runat="server" 
                    Text='<%# Eval("CatagoryName") %>'>
            </emptydatatemplate>
        
    
    </div>
    </form>
</body>
</html>



i am getting the error in sqlquery that syntax error near )

can anyone figure it out..
Posted

For god's sake - use the tools that come with Visual Studio, put a try/catch block around your code, and run it under the debugger.
 
Share this answer
 
Comments
codegeekalpha 24-Aug-11 7:33am    
i don't want to use visual studio tools
look at this line :
SqlDataAdapter da = new SqlDataAdapter("Select * from ESK_Products where CategoryID='"+Request.QueryString["CategoryID"]+"')", conn);


It has to be like :
SqlDataAdapter da = new SqlDataAdapter("Select * from ESK_Products where CategoryID='"+Request.QueryString["CategoryID"]+"'", conn);


If you observer closely, you have put redundant ")" at the end.

Hope this solved your problem.
All the best.
 
Share this answer
 
Replce your query with this..

SqlDataAdapter da = new SqlDataAdapter("Select * from ESK_Products where CategoryID='"+Request.QueryString["CategoryID"]+"'", conn);


Needed only one closing bracket..
 
Share this answer
 
v2

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