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

📄 default.aspx.cs

📁 一个ASP.NET下的中文内容管理和社区系统
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace ASPNET.StarterKit.Communities.Admin.EditSections
{
	/// <summary>
	/// Summary description for _Default.
	/// </summary>
	public class _Default : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.DataGrid dgrdSections;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// Put user code to initialize the page here
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.dgrdSections.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.Item_Click);
			this.dgrdSections.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.DataGrid_ItemDataBound);
			this.Load += new System.EventHandler(this.Page_Load);
			this.PreRender += new System.EventHandler(this.Page_PreRender);

		}
		#endregion


		//*******************************************************
		//
		// Bind the list of sections to the DataGrid.
		//
		//*******************************************************
	    
		void Page_PreRender(Object s, EventArgs e) {
			// Bind the list of Sections
			dgrdSections.ItemDataBound += new DataGridItemEventHandler(DataGrid_ItemDataBound);
			dgrdSections.DataSource = SectionUtility.GetAllSectionsFromDB();
			dgrdSections.DataKeyField = "section_ID";
			dgrdSections.DataBind();
		}
	    
		//*******************************************************
		//
		// When binding sections to the DataGrid, don't
		// show delete link for sections with children
		// and don't show order arrows for system sections.
		//
		//*******************************************************
	    
		void DataGrid_ItemDataBound(Object s, DataGridItemEventArgs e) {
			// skip if no dataitem
			if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
	    
				// don't display delete link for sections with children or system sections
				int childCount = (int)DataBinder.Eval(e.Item.DataItem, "ChildCount");
				bool system = (bool)DataBinder.Eval(e.Item.DataItem, "section_isSystem");
				if (childCount > 0 || system)
					e.Item.Cells[2].Controls.Clear();
				else {
					// Add confirmation to delete button
					string sectionName = (string)DataBinder.Eval(e.Item.DataItem, "section_name");
					ImageButton btnDelete = (ImageButton)e.Item.FindControl("btnDelete");
					btnDelete.Attributes.Add("onclick",String.Format("return confirm('Are you sure you want to delete the \"{0}\" section?')", sectionName));
				}
	    
				// Show proper home image
				ImageButton btnHome = (ImageButton)e.Item.FindControl("btnHome");
				int parentID = (int)DataBinder.Eval(e.Item.DataItem, "section_parentID");
				if (parentID == -1)
					btnHome.ImageUrl = "../Images/Home.gif";
				else
					btnHome.ImageUrl = "../Images/Home_Ghost.gif";
	    
				// Remove sort buttons for system sections
				if (system) {
					e.Item.Cells[3].Controls.Clear();
					e.Item.Cells[4].Controls.Clear();
				}
			}
		}
	    
		//*******************************************************
		//
		// User clicked the Delete link, display delete
		// warning.
		//
		//*******************************************************
	    
		void Item_Click(Object s, DataGridCommandEventArgs e) {
			int sectionID = (int)dgrdSections.DataKeys[e.Item.ItemIndex];
			switch (e.CommandName) {
				case "Delete":
					AdminUtility.DeleteSection(sectionID);
					break;
				case "Up":
					AdminUtility.MoveSectionUp(sectionID);
					break;
				case "Down":
					AdminUtility.MoveSectionDown(sectionID);
					break;
				case "Home":
					AdminUtility.MakeSectionHome(sectionID);
					break;
			}
		}




	}
}

⌨️ 快捷键说明

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