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:
<<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
dbcon obj = new dbcon();
protected void Page_Load(object sender, EventArgs e)
{
LoadGridView();
}
private void LoadGridView()
{
string query="Select CategoryID,CategoryName from Categories";
DataSet ds=obj.fillgrid(query);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
and code for product catalog.aspx page asp
<<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">
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</p>
</p
>
code for product catalog.aspx page C#
<pre lang="c#"><pre>dbcon obj = new dbcon();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadGridView();
}
}
private void LoadGridView()
{
string query="Select * from Products where CategoryID='" + Request.QueryString["ID"] + "'";
DataSet ds=obj.fillgrid(query);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind(); ;
}
protected string GetShortDescription(string longdesc)
{
if (longdesc.Length <= 255)
{
return longdesc;
}
else
{
return longdesc.Substring(0, 255) + "...";
}
}