Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I retrieve the images by the Product,aspx using a HTTP handler ShowImage.aspx all the images are displayed . But the problem is that when I click on the image button for looking the product details of a particular product then the details of all the products are displayed . I need the details of that product which has been clicked by the Image button The pages of coding I am pasting here
Show me the way please
Sincerely Yours
Upendra

Database fields
p_id int Unchecked (Identity)
p_name varchar(50) Checked (storing the urls of images)
brand varchar(50) Checked (brand name of the product)
p_file image Checked (storing the image)
price int Checked (price of the product)
description text Checked (Descriptin of the product)


Product.aspx
XML
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Product.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:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <br />
        <asp:SqlDataSource ID="SqlDataSource1" runat="server"
            ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
            SelectCommand="SELECT [p_id],[p_name], [brand], [p_file], [price] FROM [mobile]">
        </asp:SqlDataSource>
        <br />
        <br />
        <asp:DataList ID="DataList1" runat="server" DataKeyField="p_id"
            DataSourceID="SqlDataSource1" RepeatColumns="4"
            RepeatDirection="Horizontal">
            <ItemTemplate>

          <asp:ImageButton ID="ImageButton2" runat="server" ImageUrl='<%#"ShowImage.ashx?p_id="+ Eval("p_id")%>' Height="150px" Width="150px" PostBackUrl='<%# String.Format("~/ProductDetails.aspx?p_id={0}", Eval("p_id"))%>' ></asp:ImageButton>

            /ItemTemplate>
        </asp:DataList>

    </div>
    </form>
</body> </html>
Posted
Updated 8-Mar-12 18:23pm
v2
Comments
walterhevedeich 9-Mar-12 1:32am    
Can you show the code on ProductDetails.aspx, particularly on the part where you retrieve your records? I'm suspecting you just need to include a WHERE condition on the query that pulls the data, so that only the item will be retrieved.
Member 8511342 10-Mar-12 2:33am    
Hi
walterhevedeich

Here is the code of remaining two files productdetails.aspx and a Http Handler file .
Thanks a lot

ProductDetails.aspx

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

<!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:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [p_id], [p_name], [brand], [price], [description] FROM [mobile]">

<asp:DataList ID="DataList1" runat="server" Width="319px" DataKeyField="p_id"
DataSourceID="SqlDataSource1" DataMember="DefaultView">
<itemtemplate>


<asp:Image ID="Image2" runat="server"
ImageUrl='<%# String.Format("~/ShowImage.ashx?p_id={0}", Eval("p_id"))%>' />

description:
<asp:Label ID="descriptionLabel" runat="server"
Text='<%# Eval("description") %>' />
<br />
<br />





</div>
</form>
</body>
</html>

ShowImage.ashx

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

<!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:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [p_id], [p_name], [brand], [price], [description] FROM [mobile]">


<asp:DataList ID="DataList1" runat="server" Width="319px" DataKeyField="p_id"
DataSourceID="SqlDataSource1" DataMember="DefaultView">
<itemtemplate>



<asp:Image ID="Image2" runat="server"
ImageUrl='<%# String.Format("~/ShowImage.ashx?p_id={0}", Eval("p_id"))%>' />

description:
<asp:Label ID="descriptionLabel" runat="server"
Text='<%# Eval("description") %>' />
<br />
<br />








</div>
</form>
</body>
</html>

1 solution

Hi,
in pageload event of showimages.aspx
write following code

C#
protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!IsPostBack)
            {
                    string p_id= Request.QueryString["p_id"].ToString();
// after getting pat id write code to retrive product information                    

            }
        }
        catch (Exception Ex)
        {
            
        }
    }



best luck
 
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