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:
|
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(); } } }