后台:
foreach (DataListItem item in dlContent.Items)
{ System.Web.UI.WebControls.Image img = (System.Web.UI.WebControls.Image)item.FindControl("userphoto");string fileName = Request.PhysicalApplicationPath + img.ImageUrl.Replace("/", @"\");
System.Drawing.Bitmap objPic = new System.Drawing.Bitmap(fileName); int height = objPic.Height; int width = objPic.Width; if (height >= width) img.Attributes["height"] = "130"; else { img.Attributes["width"] = "100"; }}前台:<asp:Image ID="userphoto" ImageUrl='<%# Eval("filename") %>' runat="server" CssClass="image"/>