0
votes

I have a DataList control on a page. Inside ItemTemplate I have an Image and a Label control. The page get the imageurl from an sql query. The images those are shown in the image control have variable width and height. I want to set it to 160x100(wxh). I can calculate the width ratio and height ratio and have it not increased to more than 160x100.

Not sure how can i resize image control width and height programatically, for each item in datalist.

1

1 Answers

0
votes

You can resize image on ItemDataBound event. Try below code.

protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {

                      // get image option if in grid or from datasource using DataBinder.Eval()
                    Image im1 = (Image)e.Item.FindControl("Image1");                                     
                    im1.Width = "Your Width";      
                    im1.height = "Your Height";

        }
    }