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

📄 categorytagcontrol.cs

📁 community server 源码
💻 CS
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Collections;
using System.Web.UI;
using System.Web.UI.WebControls;
using CommunityServer.Blogs.Components;

namespace CommunityServer.Blogs.Controls
{
	/// <summary>
	/// Summary description for CategoryTagControl.
	/// </summary>
	public class CategoryTagControl : WeblogThemedControl
	{
		public CategoryTagControl()
		{
	
		}

		private bool _linkToTagBrowswer = true;
		public bool LinkToTagBrowser
		{
			get
			{
				return _linkToTagBrowswer;
			}
			set
			{
				_linkToTagBrowswer = value;
			}
		}

        private Repeater categories;

        private ArrayList _data;
        public ArrayList DataSource
        {
            get
            {
                return _data;
            }
            set
            {
                _data = value;
            }
        }

        public override void DataBind()
        {
            base.DataBind ();

            if(categories != null && DataSource != null && DataSource.Count > 0)
            {
                categories.DataSource = DataSource;
                categories.DataBind();
            }
        }

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender (e);

            if(categories == null || DataSource == null || DataSource.Count == 0)
                this.Visible = false;
        }

        /// <summary>
	    /// Override this method to attach templated or external skin controls to local references.
	    /// </summary>
	    /// <remarks>
	    /// This will only be called if the non-default skin is used.
	    /// </remarks>
	    protected override void AttachChildControls()
	    {
	        categories = FindControl("Categories") as Repeater;
            if(categories != null)
                categories.ItemDataBound +=new RepeaterItemEventHandler(categories_ItemDataBound);
        }

        private void categories_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                HyperLink link = e.Item.FindControl("Link") as HyperLink;
                if(link != null)
                {
                    CategoryTag tag = e.Item.DataItem as CategoryTag;
                    if(tag != null)
                    {
                        link.Text = tag.Name;

						if (this.LinkToTagBrowser)
							link.NavigateUrl = BlogUrls.Instance().TagsBrowser(this.CurrentWeblog.ApplicationKey, new string[] {tag.Name});
						else
							link.NavigateUrl = BlogUrls.Instance().IndividualCategoryPage(this.CurrentWeblog.ApplicationKey, tag.CategoryID);

                        link.Attributes.Add("rel","tag");
                        
                    }
                }
            }
        }
    }
}

⌨️ 快捷键说明

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