Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,
I have a Repeater inside which I have an Image button.
Now,the images which are coming from the datebase are of varying dimensions.
I want to resize all the images to a specified dimension,200x200 say.
1.How to do that?
Posted

1 solution

You should simply set Width and Height property of the <asp:imagebutton xmlns:asp="#unknown"></asp:imagebutton> property that you are using inside the <asp:repeater xmlns:asp="#unknown"></asp:repeater>. This should set a fixed size for the image buttons.

Alternatively, you can set the Width and Height in the CodeBehind as follows:

C#
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {
            ImageButton imgBtn = e.Item.FindControl("Imge1") as ImageButton;
            if (imgBtn != null)
            {
                imgBtn.Width = 200;
                imgBtn.Height = 200;
            }
        }
}


However, if you want to resize your actual image that you retrieve from the database, you need to resize it using the API available in .NET (GDI+) framework. That would be expensive in terms of performance though.
 
Share this answer
 
Comments
avishekrc 19-Aug-10 8:05am    
Thanks dude!but at the same time,is there any way to keep their Aspect ratio(Width:Height) unaltered?
Al-Farooque Shubho 19-Aug-10 9:38am    
If you set width and height, the aspect ratio is not honored. For that, I think you have to do image processing.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900