ImageField不具有id公共属性,怎么使图片按比例缩小?
一般的限制长宽会使图片变性的, 要按比例才好, 不过ImageField没有id属性, 网上找的这个办法就不行了.
有没有别的解决办法?
protected void Page_Load(object sender, EventArgs e) { if (Session["UserName"] == null) Response.Redirect("../index.aspx"); if (!IsPostBack) { this.PhotoDataBind(); SetimageSize(RroImage, 950); } }public void SetimageSize(System.Web.UI.HtmlControls.HtmlImage Image, int MaxW){System.Drawing.Image img = System.Drawing.Image.FromFile(Page.Server.MapPath(Image.Src.Replace("..", "")));if (img.Width > MaxW){int Nw = Convert.ToInt32((float)img.Width - ((float)img.Width - (float)570));int Nh = Convert.ToInt32((float)img.Height / ((float)img.Width / (float)Nw));Image.Width = Nw;Image.Height = Nh;Image.Alt = String.Format("图片自动缩小 Size:{0}×{1}", Nw, Nh);} }<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" OnRowDeleting="GridView1_RowDeleting" DataKeyNames="PhotoID" > <Columns> <asp:BoundField DataField="PhotoID" HeaderText="ID" /> <asp:BoundField DataField="PhotoUser" HeaderText="用户" /> <asp:ImageField DataImageUrlField="PhotoPath" HeaderText="缩略图"/> <asp:CommandField HeaderText="删除" ShowDeleteButton="True" /> <%--Field不具有id属性--%> </Columns> </asp:GridView>