示例#1
0
        /// <summary>
        /// Handles the ItemDataBound event of the dgProductImages control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.Web.UI.WebControls.DataGridItemEventArgs"/> instance containing the event data.</param>
        void dgProductImages_ItemDataBound(object sender, DataGridItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                LinkButton editButton = e.Item.Cells[0].FindControl("lbEdit") as LinkButton;
                if (editButton != null)
                {
                    editButton.Text = LocalizationUtility.GetText("lblEdit");
                }
                LinkButton deleteButton = e.Item.Cells[4].FindControl("lbDelete") as LinkButton;
                if (deleteButton != null)
                {
                    deleteButton.Text = LocalizationUtility.GetText("lblDelete");
                    deleteButton.Attributes.Add("onclick", "return confirm(\"" + LocalizationUtility.GetText("lblConfirmDelete") + "\");return false;");
                }

                System.Web.UI.WebControls.Image image = e.Item.Cells[3].FindControl("productImage") as System.Web.UI.WebControls.Image;
                if (image != null)
                {
                    string mappedPath = HttpContext.Current.Server.MapPath(image.ImageUrl);
                    if (File.Exists(mappedPath))
                    {
                        using (System.Drawing.Image drawnImage = System.Drawing.Image.FromFile(mappedPath)) {
                            //do a little simple scaling
                            //landscape
                            if (drawnImage.Width > drawnImage.Height)
                            {
                                if (drawnImage.Width > 90)
                                {
                                    image.Width  = 90;
                                    image.Height = drawnImage.Height * 90 / drawnImage.Width;
                                }
                            }
                            else //portrait
                            {
                                if (drawnImage.Height > 90)
                                {
                                    image.Height = 90;
                                    image.Width  = drawnImage.Width * 90 / drawnImage.Height;
                                }
                            }
                        }
                        HyperLink hoverlink = e.Item.Cells[3].FindControl("hlImage") as HyperLink;
                        if (hoverlink != null)
                        {
                            LocalizationUtility.AddHoverHtml(hoverlink, string.Format("<img border=\"0\" src=\"{0}\"/>", Page.ResolveUrl(image.ImageUrl)));
                        }
                    }
                }
            }
        }