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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Abhishek JainPosted Aug 17, 2013, 2:39 AM
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;
}
}
Iftikar HussainPosted Aug 17, 2013, 1:53 AM
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