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

📄 defaultcs.aspx.cs

📁 Telerik是很大的第三方软件制造商
💻 CS
字号:
using System;
using Telerik.QuickStart.Grid;
using Telerik.WebControls;
using System.Web.UI.WebControls;
using Telerik.QuickStart;

namespace Telerik.GridExamplesCSharp.Programming.GroupBy
{
	public abstract class DefaultCS : XhtmlPage
	{
		protected System.Web.UI.WebControls.DataGrid DataGrid1;
		protected System.Web.UI.WebControls.Button Button1;
		protected System.Web.UI.WebControls.LinkButton Linkbutton2;
		protected System.Web.UI.WebControls.LinkButton Linkbutton1;
		protected System.Web.UI.WebControls.LinkButton Linkbutton4;
		protected System.Web.UI.WebControls.LinkButton Button2;
		protected System.Web.UI.WebControls.PlaceHolder PlaceHolder1;
		protected Telerik.WebControls.RadGrid RadGrid1;

		#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);
		}
		
		///		Required method for Designer support - do not modify
		///		the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.Load += new System.EventHandler(this.Page_Load);
		}
		#endregion

		private void RadGrid1_NeedDataSource(object source, Telerik.WebControls.GridNeedDataSourceEventArgs e)
		{
			RadGrid1.DataSource = DataSourceHelperCS.GetDataTable("Select * from Customers");
		}

		private void RadGrid1_DetailTableDataBind(object source, Telerik.WebControls.GridDetailTableDataBindEventArgs e)
		{
			GridDataItem parentItem = e.DetailTableView.ParentItem as GridDataItem;
			if ( parentItem.Edit )
			{
				return;
			}

			if ( e.DetailTableView.DataMember == "Orders" )
			{
				e.DetailTableView.DataSource = DataSourceHelperCS.GetDataTable("Select * from Orders where CustomerID = '" 
					+ parentItem["CustomerID"].Text + "'");
			}
			else
				if ( e.DetailTableView.DataMember == "OrderDetails" )
			{
				e.DetailTableView.DataSource = DataSourceHelperCS.GetDataTable( "Select * from [Order Details] where OrderID = " + 
					parentItem["OrderID"].Text );				
			}
		}

		private void Page_Load(object sender, System.EventArgs e)
		{
			this.RadGrid1 = new RadGrid();
			
			//Add the RadGrid instance to the controls
			this.PlaceHolder1.Controls.Add( RadGrid1 );

			this.RadGrid1.NeedDataSource += new GridNeedDataSourceEventHandler(this.RadGrid1_NeedDataSource);
			this.RadGrid1.DetailTableDataBind += new  GridDetailTableDataBindEventHandler(this.RadGrid1_DetailTableDataBind);
			
			if ( !IsPostBack )
			{
				this.RadGrid1.CssClass = "RadGrid";

				this.RadGrid1.Width = Unit.Percentage(100);
				this.RadGrid1.PageSize = 5;
				this.RadGrid1.AllowPaging = true;
				this.RadGrid1.AutoGenerateColumns = false;

				this.RadGrid1.AllowSorting = true;

				this.RadGrid1.MasterTableView.RetrieveAllDataFields = false;
				this.RadGrid1.MasterTableView.AdditionalDataFieldNames = new string[] {"Country"};

				//Set options to enable Group-by 
				this.RadGrid1.GroupingEnabled = true;
				this.RadGrid1.ShowGroupPanel = true;
				this.RadGrid1.ClientSettings.AllowDragToGroup = true;
				this.RadGrid1.ClientSettings.AllowColumnsReorder = true;

				//Add Customers table
				this.RadGrid1.MasterTableView.DataMember = "Customers";
				this.RadGrid1.MasterTableView.PageSize = 15;

				this.RadGrid1.Columns.Clear();
				this.RadGrid1.MasterTableView.DetailTables.Clear();

				GridBoundColumn boundColumn;
				boundColumn = new GridBoundColumn();
				this.RadGrid1.MasterTableView.Columns.Add(boundColumn);				
				boundColumn.DataField = "CustomerID";
				boundColumn.HeaderText = "CustomerID";

				boundColumn = new GridBoundColumn();
				this.RadGrid1.MasterTableView.Columns.Add(boundColumn);
				boundColumn.DataField = "ContactName";
				boundColumn.HeaderText = "Contact Name";

				//Add Orders table
				GridTableView tableViewOrders = new GridTableView(RadGrid1);
				this.RadGrid1.MasterTableView.DetailTables.Add( tableViewOrders );
				tableViewOrders.DataMember = "Orders";

				//Add a group-by expression as string into Customer's collection
				this.RadGrid1.MasterTableView.GroupByExpressions.Add( new GridGroupByExpression("Country Group By Country") );

				//Add a group-by expression by defining fields into Orders' collection
				GridGroupByExpression expression = new GridGroupByExpression();

				GridGroupByField gridGroupByField = new GridGroupByField();
			
				//Add select fileds (before the "Group By" clause)
				gridGroupByField = new GridGroupByField();
				gridGroupByField.FieldName = "EmployeeID";
				gridGroupByField.HeaderText = "Employee";
				gridGroupByField.HeaderValueSeparator = " for current group: ";
				gridGroupByField.FormatString = "<strong>{0}</strong>";
				expression.SelectFields.Add( gridGroupByField );

				gridGroupByField = new GridGroupByField();
				gridGroupByField.FieldName = "Freight";
				gridGroupByField.HeaderText = "Total shipping cost is ";
				gridGroupByField.HeaderValueSeparator = "";
				gridGroupByField.FormatString = "<strong>{0:0.00}</strong>";
				gridGroupByField.Aggregate = GridAggregateFunction.Sum;
				expression.SelectFields.Add( gridGroupByField );

				//Add a filed for group-by (after the "Group By" clause) 
				gridGroupByField = new GridGroupByField();
				gridGroupByField.FieldName = "EmployeeID";
				expression.GroupByFields.Add( gridGroupByField );

				//This expression as string would look like:
				// "RequiredDate, Freight Group By RequiredDate"
				//but the display format of filed values wolld be different
				tableViewOrders.GroupByExpressions.Add( expression );

				boundColumn = new GridBoundColumn();
				tableViewOrders.Columns.Add(boundColumn);
				boundColumn.DataField = "OrderID";
				boundColumn.HeaderText = "OrderID";

				boundColumn = new GridBoundColumn();
				tableViewOrders.Columns.Add(boundColumn);
				boundColumn.DataField = "OrderDate";
				boundColumn.HeaderText = "Date Ordered";
			}			
		}
	}
}

⌨️ 快捷键说明

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