• DataList Image Nhibernate 数据绑定

    日期:2009-03-12 | 分类:.net

    版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
    http://alek.blogbus.com/logs/36470574.html

       protected void DataListImages_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Tjgdcpic info = (Tjgdcpic)e.Item.DataItem;

                Image Image1 = (Image)e.Item.FindControl("Image1");

                //xjjgdc_images
                AppSettingsReader reader = new AppSettingsReader();
                string image_locate = reader.GetValue("Image_locate", typeof(string)).ToString().Trim();

                Image1.ImageUrl = image_locate + info.Realfilename;

                string image_file_name =info.Realpath.Trim() + "\\" + info.Realfilename;
                if (System.IO.File.Exists(image_file_name))
                {
                    using (System.Drawing.Image img = System.Drawing.Image.FromFile(image_file_name))
                    {
                        if ((img.Width > 640) || (img.Height > 640))
                        {
                            //
                            decimal width = img.Width;
                            decimal height = img.Height;
                            int newwidth, newheight;

                            string fbl_str = reader.GetValue("PicZuiDaFenbianlv", typeof(string)).ToString().Trim();
                            int fbl = int.Parse(fbl_str);

                            if (width > height)
                            {
                                newwidth = fbl;
                                newheight = (int)(height / width * fbl);
                            }
                            else
                            {
                                newheight = fbl;
                                newwidth = (int)(width / height * fbl);
                            }
                            Image1.Width = newwidth;
                            Image1.Height = newheight;
                        }
                        else
                        {
                            Image1.Width = img.Width;
                            Image1.Height = img.Height;
                        }
                    }
                }

            }
        }


    收藏到:Del.icio.us