plz help me with this ......i m not able to fetch the image from database in datalist
plz send me the code...plzz thnx
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 16, 2013, 9:53 PM EDT
How you are saving the image in your database? is it in byte format or the path?
please refer the below link
http://www.ezzylearning.com/tutorial.aspx?tid=1399196
Regards,
Iftikar
Abhishek JainRank #1,062 · 1.8K reputationPosted Aug 16, 2013, 10:39 PM EDT
If the datatype of the image in Database is of type image then use this code:
public class Images
{
public byte[] Image { get; set;}
}
protected void Page_Load(object sender, EventArgs e)
{
List
//Get the data from the Database and fill it into the image list
dlImages.DataSource = imageList;
dlImages.DataBind();
}
protected void dlImages_OnItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
Byte[] imgByte = null;
imgByte = ((Images)e.Item.DataItem).Image;
Image image = (Image)e.FindControl("testImage");
image.ImageUrl = "data:image/jpg;base64," + Convert.ToBase64String(imgByte);
}
}
If the datatype of the image in Database is of type varchar containing base64 string then use this code:
public class Images
{
public string Image { get; set;}
}
protected void Page_Load(object sender, EventArgs e)
{
List
//Get the data from the Database and fill it into the image list
dlImages.DataSource = imageList;
dlImages.DataBind();
}
protected void dlImages_OnItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
string imageStream = string.Empty;
imageStream = ((Images)e.Item.DataItem).Image;
Image image = (Image)e.FindControl("testImage");
image.ImageUrl = "data:image/jpg;base64," + imageStream);
}
}
If the datatype of the image in Database is of type varchar containing imageUrL then use this code:
public class Images
{
public string ImageURL { get; set;}
}
protected void Page_Load(object sender, EventArgs e)
{
List
//Get the data from the Database and fill it into the image list
dlImages.DataSource = imageList;
dlImages.DataBind();
}
protected void dlImages_OnItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
string imageURL = string.Empty;
imageURL = ((Images)e.Item.DataItem).Image;
Image image = (Image)e.FindControl("testImage");
image.ImageUrl = imageURL;
}
}