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

📄 itemtopic.cs

📁 ASP.NET精品全站程序SQL版.rar
💻 CS
字号:
namespace ASPNET.StarterKit.Communities {

    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;


    //*********************************************************************
    //
    // ItemTopic Class
    //
    // This control displays either a topic name or topic image that
    // links to the Topic page.
    //
    //*********************************************************************
    
    public class ItemTopic : WebControl {
    
    
        public ItemTopic() : base() {
            CssClass = "ItemTopic";
            EnableViewState = false;
        }

       
        public string Name {
            get {   
                if (ViewState["Name"] == null)
                    return String.Empty;
                 else
                    return (string)ViewState["Name"];
            }
            set { ViewState["Name"] = value; }
        
        }


        public string Image {
            get {   
                if (ViewState["Image"] == null)
                    return String.Empty;
                 else
                    return (string)ViewState["Image"];
            }
            set { ViewState["Image"] = value; }
        
        }
       
       
        override protected void OnDataBinding(EventArgs e) {
            ContentItem item;

            if (NamingContainer is ContentItem)
                item = (ContentItem)NamingContainer;
            else
                item = (ContentItem)NamingContainer.NamingContainer;


            ContentInfo objContentInfo = (ContentInfo)item.DataItem;
            ViewState["Name"] = objContentInfo.TopicName;
            ViewState["Image"] = objContentInfo.TopicImage;
        }
      
       
        
        //*********************************************************************
        //
        // Render Method
        //
        // Only render if topics are enabled. We need to check for the existence
        // of context to avoid a Designer error in Visual Studio .NET
        //
        //*********************************************************************

        protected override void Render(HtmlTextWriter tw) {
            if (Context != null) {
                SectionInfo objSectionInfo = (SectionInfo)Context.Items["SectionInfo"];
            
                if (objSectionInfo.EnableTopics)
                    base.Render(tw);
            } 
        }
       
        
        //*********************************************************************
        //
        // RenderContents Method
        //
        // Renders either the name or image for the topic.
        //
        //*********************************************************************

        protected override void RenderContents(HtmlTextWriter tw) {
            string imageTag;
            string imagePath;
               
            // Calculate topic path
            string topicPath = String.Format("~/Topic.aspx?topic={0}", Context.Server.UrlEncode(Name));
            topicPath = Page.ResolveUrl(topicPath); 
            
            
            tw.AddAttribute(HtmlTextWriterAttribute.Href, topicPath);
            tw.RenderBeginTag(HtmlTextWriterTag.A);
            if (Image == String.Empty)
                tw.Write( Name );
            else {
                imagePath = Page.ResolveUrl( "~/" + Image);
                imageTag = String.Format("<img src=\"{0}\" ALT=\"{1}\" border=\"0\">", imagePath, Name);
                tw.Write(imageTag);
            }
            tw.RenderEndTag();
        }


    }
}

⌨️ 快捷键说明

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