itemeventlocation.cs

来自「完全网站系统」· CS 代码 · 共 101 行

CS
101
字号
namespace ASPNET.StarterKit.Communities {
    using System;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using ASPNET.StarterKit.Communities.Events;
    using System.ComponentModel;



    //*********************************************************************
    //
    // ItemEventLocation Class
    //
    // Represents an event location displayed in a template
    //
    //*********************************************************************

	public class ItemEventLocation : WebControl {

        private string _formatString = "location: {0}";

    
        //*********************************************************************
        //
        // ItemEventLocation Constructor
        //
        // Assign a default css class
        //
        //*********************************************************************
		public ItemEventLocation() {
			CssClass = "itemEventLocation";
			EnableViewState = false;
		}

    
        //*********************************************************************
        //
        // FormatString Property
        //
        // String used for formatting location
        //
        //*********************************************************************
        public string FormatString {
            get {return _formatString;}
            set {_formatString = value;}
        }

    
        //*********************************************************************
        //
        // OnDataBinding Method
        //
        // Get the content info from the container
        //
        //*********************************************************************

        override protected void OnDataBinding(EventArgs e) {
            ContentItem item;

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


            EventInfo objEventInfo = (EventInfo)item.DataItem;
            ViewState["EventLocation"] = objEventInfo.Location;
        }

   
        //*********************************************************************
        //
        // Render Method
        //
        // Render only if there is a value
        //
        //*********************************************************************

        override protected void Render(HtmlTextWriter writer) {
            if ((string)ViewState["EventLocation"] != String.Empty)
                base.Render(writer);    
        }

    
        //*********************************************************************
        //
        // RenderContents Method
        //
        // Render the contents
        //
        //*********************************************************************

        override protected void RenderContents(HtmlTextWriter writer) {
            writer.Write(String.Format(_formatString, HttpUtility.HtmlEncode((string)ViewState["EventLocation"])));    
        }


    }
}

⌨️ 快捷键说明

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