0% found this document useful (0 votes)
40 views

Image

This document discusses three ways of inserting and displaying images in ASP.NET: 1. Uploading an image file, saving it to a folder, and retrieving information like the filename. 2. Retrieving an image from a folder and binding it to an <asp:Image> control in a DataList. 3. Retrieving an image from a database, checking for a default image if needed, and setting the image size to a maximum while displaying it in an <asp:Image> control.

Uploaded by

api-3848319
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Image

This document discusses three ways of inserting and displaying images in ASP.NET: 1. Uploading an image file, saving it to a folder, and retrieving information like the filename. 2. Retrieving an image from a folder and binding it to an <asp:Image> control in a DataList. 3. Retrieving an image from a database, checking for a default image if needed, and setting the image size to a maximum while displaying it in an <asp:Image> control.

Uploaded by

api-3848319
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Image Inserting:

if (flpup.PostedFile.FileName != "")
{
if(flpup.PostedFile.ContentType.StartsWith("image"))
{
img =
flpup.PostedFile.FileName.Substring(flpup.PostedFile.FileName.LastIndex
Of("\\") + 1);
s = id.ToString() + "_" + img;
flpup.PostedFile.SaveAs(Server.MapPath("listing\\" + s));
}
else
{
lblerror.Visible=true;
lblerror.Text="Please Upload images Only";
}
}
else
{
img = "NO-Image";
}

Retriving an image from folder to DATALIST:

<tr>
<td colspan="2" align="center" class="membertextinside" ><asp:Image
ID="img" runat="server"
ImageUrl='<%#"listing/"+DataBinder.Eval(Container.DataItem,"addlogo")
%>' />
</td>
</tr>

Displaying an image from database with fixed size:

SqlDataAdapter da = new SqlDataAdapter("select * from listing1 where


tblid = '" + Session["tblid"].ToString() + "'", cn);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
foreach (DataRow dr in ds.Tables[0].Rows)

{
if (dr["addlogo"].ToString() == "")
{
//System.Web.UI.WebControls.Image im =
((System.Web.UI.WebControls.Image).FindControl("img"));
img.ImageUrl = "images/" + "no-img.jpg";

}
else
{
System.Drawing.Image i =
System.Drawing.Image.FromFile(Server.MapPath("listing/" +
dr["addlogo"].ToString()));
//img.ImageUrl = "listing/" +
dr["addlogo"].ToString();
float h = i.Height;
float w = i.Width;
//float height, width;
if (w > 500)
{
//System.Web.UI.WebControls.Image im =
((System.Web.UI.WebControls.Image).FindControl("img"));
img.Width = 500;
}
if (h > 100)
{
img.Height = 100;
}
img.ImageUrl = "listing/" +
dr["addlogo"].ToString();

}
}

You might also like