Click here to Skip to main content
15,885,956 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
display data and image in datalist on click of  search button(like real estate website)
  protected void Page_Load(object sender, EventArgs e)
    {
        //lbl_msg.Text = Request.QueryString["name"].ToString();
        want = Request.QueryString["want"].ToString();
        bedroom=Convert.ToInt32(Request.QueryString["bedroom"]);
        city = Request.QueryString["city"].ToString();
        type=Request.QueryString["type"].ToString();
        budgetmin = Convert.ToInt32(Request.QueryString["budgetmin"]);
        budgetmax = Convert.ToInt32(Request.QueryString["budgetmax"]);
        location = Request.QueryString["location"].ToString();
        datalistsearchresult();

    }
    public void datalistsearchresult()
    {
        if (this.connopen() == true)
        {
            try
            {
                //query = ("select property_img,bedroom,pdiscription,contact_no,city,location,budget from residential where bedroom=" + bedroom + " and city='" + city + "' and budget between " + budgetmin + " and " + budgetmax + " and location='" + location + "'");
                //da = new SqlDataAdapter(query, connect);
                //ds = new DataSet();
                //da.Fill(ds, "residential");
                cmd = new SqlCommand("select property_img,bedroom,pdiscription,contact_no,city,location,budget from residential where bedroom=" + bedroom + " and city='" + city + "' and budget between " + budgetmin + " and " + budgetmax + " and location='" + location + "'",sqlconn);
                dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    byte[] imgData = (byte[])dr["property_img"];
                    Response.BinaryWrite(imgData);
                    

                }
                DataList1.DataSource = dr;
                DataList1.DataBind();
                connclose();
            }
            catch(Exception ex)
            {
                connclose();
            }
        }
    
    }
<asp:DataList ID="DataList1" runat="server">
    <ItemTemplate>
        <asp:Image ID="Image1" runat="server" ImageUrl='<%#Eval("property_img")%>' Height="98px" Width="200px" />
        <asp:Label ID="Label1" runat="server" Text='<%#Eval("bedroom")%>'></asp:Label>
        <asp:Label ID="Label2" runat="server" Text='<%#Eval("pdiscription")%>'></asp:Label>
        <asp:Label ID="Label3" runat="server" Text='<%#Eval("city")%>'></asp:Label>
        <asp:Label ID="Label4" runat="server" Text='<%#Eval("location")%>'></asp:Label>
        <asp:Label ID="Label5" runat="server" Text='<%#Eval("budget")%>'></asp:Label>
        <asp:Label ID="Label6" runat="server" Text='<%#Eval("contact_no")%>'></asp:Label>
    </ItemTemplate>
    </asp:DataList>
Posted
Updated 29-Nov-12 2:22am
v5

1 solution

where you store image in database using http handler in binary format or in folder saving the path in database.
 
Share this answer
 
Comments
prakash00060 29-Nov-12 8:37am    
when i use handler then i have to use image id.
but i have to show image in behalf of some data.
please see the query.
this query is run on sql.

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