Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Hello Experts,
I have developed web application .In that application i want to display images on datalist control.I tried lot but i got only cross mark instead of actual image.

Please help me........
Posted
Comments
Thanks7872 20-Aug-15 2:52am    
Mention details. In its current from,the question is not clear. No one can assume why no image is there.
SujataJK 20-Aug-15 3:11am    
Thanx for ur reply...

My designing page include DataList control like that
<asp:DataList ID="DataList1" runat="server" RepeatColumns="4" RepeatDirection="Horizontal"Width="100%" BorderColor="Blue" BorderStyle="Solid" BorderWidth="3px">

<itemtemplate>

<asp:Label ID="Label2" runat="server" Text='<%# Eval("imagename") %>' Font-Italic="true"/><br />

<asp:Image ID="Image1" runat="server" ImageUrl='<%# "GetImageDatafromDB.aspx?id=" + System.Convert.ToString(Eval("ImageID")) %>'/>

<itemstyle horizontalalign="Center" verticalalign="Top">


//Code in the pageload event
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string connectionString = ConfigurationManager.ConnectionStrings["MyConnection"].ConnectionString;
DataTable dt = new DataTable();
SqlConnection conn = new SqlConnection(connectionString);
using (conn)
{
SqlDataAdapter ad = new SqlDataAdapter("SELECT * FROM ImageGrid", conn);
ad.Fill(dt);
}
DataList1.DataSource = dt;
DataList1.DataBind();
}
}
// And the code in page load of GetImageDatafromDB.aspx
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string imageID = Request.QueryString["id"];

string constr = ConfigurationManager.ConnectionStrings["MYConnection"].ConnectionString;
string sQuery = "SELECT image FROM ImageGrid WHERE imageID = @imageID";

SqlConnection con = new SqlConnection(constr);
SqlCommand cmd = new SqlCommand(sQuery, con);

cmd.Parameters.Add("@imageID", SqlDbType.Int).Value = Int32.Parse(imageID);

using (con)
{
con.Open();
SqlDataReader DR = cmd.ExecuteReader();

if (DR.Read())
{
byte[] imgData = (byte[])DR["Image"];
Response.BinaryWrite(imgData);
}
}
}

 
Share this answer
 
Comments
SujataJK 20-Aug-15 3:23am    
thanx for ur reply .But I already used this website.It gives same problem.All other information displayed correctly only image shows cross mark.
DamithSL 20-Aug-15 3:32am    
put breakpoint GetImageDatafromDB page Page_Load method and check whether you get image data from database or not
<asp:image id="Image1" runat="server" class="thumb" imageurl="<%#Eval(" image","~="" folder="" to="" save="" image="" {0}")="" %&gt;"="" width="95" height="90" xmlns:asp="#unknown">

instead of ~/Path/image.jpg use ~/Path/{0}
 
Share this answer
 
Comments
Thanks7872 20-Aug-15 2:51am    
And who said OP used the code you corrected?
Arasappan 20-Aug-15 3:01am    
it may help u or not
SujataJK 20-Aug-15 3:25am    
see my newly posted code from details
Quote:
got only cross mark instead of actual image.
That means the path of images are wrong.

See how you are binding the path to the image control. Also inspect the image in browser developer toll to see what is the path being rendered. That will give you the hint of the issue you have with that.
 
Share this answer
 
Comments
SujataJK 20-Aug-15 3:14am    
Here i retrieve image from sql server.

See My newly posted code .
Did you check what I said you?

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