日期:2014-05-17 浏览次数:20657 次
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>