⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 photogallerysection.cs

📁 一个ASP.NET下的中文内容管理和社区系统
💻 CS
字号:
namespace ASPNET.StarterKit.Communities.PhotoGallery {

    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using ASPNET.StarterKit.Communities;


    //*********************************************************************
    //
    // PhotoGallerySection Class
    //
    // Represents the default page for the PhotoGallery section. This class 
    // displays a list of photos.
    //
    //  _skinFileName = the name of the skin to use for this section
    //
    //  _getContentItems = the name of the method that retrieves the list of content items 
    //
    //*********************************************************************

    public class PhotoGallerySection : ContentListPage {
    
        string _skinFileName = "PhotoGallery_PhotoGallerySection.ascx";

        GetContentItemsDelegate _getContentItems = new GetContentItemsDelegate(PhotoUtility.GetPhotos);
        
        
        DropDownList dropPhotoTemplates;
        Panel pnlFilmstrip;
        Image imgFullImage;
        
        string firstImage = String.Empty;

        //*********************************************************************
        //
        // InitializeSkin Method
        //
        // In this case, we need to override the InitializeSkin method since
        // we need to wire-up an ItemDataBound handler.
        //
        //*********************************************************************
        override protected void InitializeSkin(Control skin) {


            // Get list of photo templates
            dropPhotoTemplates = (DropDownList)GetControl(skin, "PhotoTemplates");
            dropPhotoTemplates.SelectedIndexChanged += new EventHandler(PhotoTemplateChanged);
            dropPhotoTemplates.AutoPostBack = true;

            // Get the panel for showing a filmstrip big image
            pnlFilmstrip = (Panel)GetControl(skin, "pnlFilmstrip");
            imgFullImage = (Image)GetControl(skin, "imgFullImage");

            // Get the ContentList that contains the photos
            objContentList = (ContentList)GetControl(skin, "ContentList" );
            objContentList.ItemDataBound += new ContentListItemEventHandler(ContentList_ItemDataBound);


            // Get Total Records
            if (!Page.IsPostBack) 
                objContentList.TotalRecords = ContentPageUtility.GetTotalRecords(objSectionInfo.ID);
            

            // Add sorting
            objSorter = (Sorter)GetOptionalControl(skin, "Sorter");
            if (objSorter != null)
                objSorter.OrderChanged += new EventHandler(ContentList_OrderChanged);

        }

        
        
        


        
        //*********************************************************************
        //
        // OnLoad Method
        //
        // Handles the Page Load event in order to initialize the current page
        // and bind the list of images to the ContentList control.
        //
        //*********************************************************************
		override protected void OnLoad(EventArgs e) {
            EnsureChildControls();

          
            // Assign the Item template
            switch (dropPhotoTemplates.SelectedItem.Value.ToLower()) {
                case "filmstrip":
                    objContentList.ItemTemplate = LoadTemplate("PhotoGallery_Filmstrip.ascx");
                    pnlFilmstrip.Visible = true;
                    break;
                default:
                    objContentList.ItemTemplate = LoadTemplate("PhotoGallery_Thumbnails.ascx");
                    pnlFilmstrip.Visible = false;
                    break;
            }
            
            if (!Page.IsPostBack)            
                BindContent();
        }



        
        //*********************************************************************
        //
        // PhotoTemplateChanged Method
        //
        // Rebind when the user selects a new template for the photos.
        //
        //*********************************************************************
        void PhotoTemplateChanged(Object s, EventArgs e) {
            BindContent();        
        }


        override protected void BindContent() {
            base.BindContent();
            imgFullImage.ImageUrl = CommunityGlobals.CalculatePath(firstImage);
        }



        void ContentList_ItemDataBound(Object s, ContentListItemEventArgs e) {
            // Skip header and footer templates                    
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
            
                // Get photo info object from data item
                PhotoInfo objPhotoInfo = (PhotoInfo)e.Item.DataItem;

 
                // Build image path
                string imagePath = ImageUtility.BuildImagePath(objPhotoInfo.ImageID, objPhotoInfo.ImageName);
  
            
                // Set first image
                if (firstImage == String.Empty)
                    firstImage = imagePath;        
                
                // Add javascript to imagelink                
                if (pnlFilmstrip.Visible) {
                    ItemPhotoImage imgThumbnail = (ItemPhotoImage)GetControl(e.Item.Controls[0], "imgThumbnail");    
                    imgThumbnail.NavigateUrl = String.Format("javascript:showImage('{0}')", imagePath);
                }
            }      
        }




        //*********************************************************************
        //
        // PhotoGallerySection Constructor
        //
        // Assigns skin and contentItems method to base ContentListPage class
        //
        //*********************************************************************
        public PhotoGallerySection() : base() {
            SkinFileName = _skinFileName;
            GetContentItems = _getContentItems;
        }








    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -