Click here to Skip to main content
15,890,336 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a gridview having categories shown in linkbuttion using templatefield in the database. and this gridview is shown in masterpage

now on clicking that linkbuttion showing categoryname from the database in gridview. i am redireting it to productcatalog.aspx page.

now on product catalog.aspx i have shown the products belonging to the particular catagory from the database.

i have show the categories table in the masterpage.

problem is that .when i clik on the catagoryname in gridview shown in linkbuttion it will show me the products from that cateory in the productcatalog.aspx page..

but when i am in productcatalog.aspx page when i click on the another catagoryname form the categories table ( as it is shown in the masterpage and is shown in entire web), the page doesnot show the products from the category .

to see the products from another catagory i have to go to some other page. and then click on the other catagory. then i will give the requested products

i am posting the code here..


code for gridview showing category names from db:
ASP.NET
<<pre>asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
    Height="74px" HorizontalAlign="Center" Width="246px">
    <Columns>
        <asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="Categories">
            <ItemTemplate>
                <asp:LinkButton ID="LinkButton1" runat="server" 
                    PostBackUrl='<%# "~/ProductCatalog.aspx?ID="+Eval("CategoryID") %>' 
                    Text='<%# Eval("CategoryName") %>'></asp:LinkButton>
                <br />
            </ItemTemplate>

<ItemStyle HorizontalAlign="Center"></ItemStyle>
        </asp:TemplateField>
    </Columns>
    <EmptyDataTemplate>
        <asp:HyperLink ID="HyperLink1" runat="server" 
            Text='<%# Eval("CatagoryName") %>'></asp:HyperLink>
    </EmptyDataTemplate>
</asp:GridView>


backend c# code for gridview showing category names from db

C#
dbcon obj = new dbcon();
   protected void Page_Load(object sender, EventArgs e)
   {
       LoadGridView();
   }
   private void LoadGridView()
   {
       //conn.Open();
       string query="Select CategoryID,CategoryName from Categories";
       DataSet ds=obj.fillgrid(query);
       GridView1.DataSource = ds.Tables[0];
       GridView1.DataBind();
       //conn.Close();




and code for product catalog.aspx page asp
C#
<<pre>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") %>'></asp:HyperLink>
                                </td>
                            </tr>
                            <tr>
                                <td align="left">
                                    <asp:Label ID="Label3" runat="server" 
                                        Text='<%# GetShortDescription(Eval("Description").ToString()) %>'></asp:Label>
                                </td>
                            </tr>
                            <tr>
                                <td align="left">
                                    <asp:Label ID="Label5" runat="server" SkinID="FormLabel" Text="Price :"></asp:Label>
                                    <asp:Label ID="Label4" runat="server" Text='<%# Eval("UnitCost", "{0:C}") %>'></asp:Label>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                    &nbsp;</td>
                            </tr>
                        </table>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    </p>
    
    </p
>



code for product catalog.aspx page C#

C#
<pre lang="c#"><pre>dbcon obj = new dbcon();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            LoadGridView();

        }

    }
    private void LoadGridView()
    {
        //conn.Open();
        string query="Select * from Products where CategoryID='" + Request.QueryString["ID"] + "'";
        //DataSet ds = new DataSet();
        DataSet ds=obj.fillgrid(query);
        GridView1.DataSource = ds.Tables[0];
        GridView1.DataBind(); ;
        //conn.Close();
    }
    protected string GetShortDescription(string longdesc)
    {
        if (longdesc.Length <= 255)
        {
            return longdesc;
        }
        else
        {
            return longdesc.Substring(0, 255) + "...";
        }
    }
Posted
Updated 12-Sep-11 9:32am
v2
Comments
Herman<T>.Instance 12-Sep-11 15:32pm    
thanks for all the code but your question is not quite clear

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