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

📄 defaultcs.aspx.cs

📁 Telerik是很大的第三方软件制造商
💻 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;
using Telerik.QuickStart;
using Telerik.WebControls;

namespace Telerik.InputExamplesCS.Functionality.DataGrid
{
	/// <summary>
	/// Summary description for DefaultCS.
	/// </summary>
	public class DefaultCS : XhtmlPage
	{
		protected System.Web.UI.WebControls.DataGrid DataGrid1;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				BindGrid();
			}
		}


		private DataTable DataSource
		{
			get
			{
				if (Session["DataGridCS"] == null)
				{
					DataTable data = new DataTable();
					data.Columns.Add("ID");
					data.Columns.Add("Title");
					data.Columns.Add("Name");
					data.Columns.Add("Birthday", typeof(DateTime));
					data.Columns.Add("SocialSecurity");
					
					data.Rows.Add(new object[]{1,"Mr.", "John Smith", new DateTime(1960, 10, 10), "111-22-3333"});
					data.Rows.Add(new object[]{2,"Mrs.", "Jane Brown", new DateTime(1972, 12, 25), "144-22-5555"});
					Session["DataGridCS"] = data;
				}
				return (DataTable)Session["DataGridCS"];
			}
		}

		private void BindGrid()
		{
			DataGrid1.DataSource = DataSource;
			DataGrid1.DataKeyField = "ID";
			DataGrid1.DataBind();
		}

		#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.DataGrid1.SelectedIndexChanged += new System.EventHandler(this.DataGrid1_SelectedIndexChanged);
			this.DataGrid1.EditCommand +=new DataGridCommandEventHandler(DataGrid1_EditCommand);
			this.DataGrid1.UpdateCommand +=new DataGridCommandEventHandler(DataGrid1_UpdateCommand);
			this.DataGrid1.CancelCommand +=new DataGridCommandEventHandler(DataGrid1_CancelCommand);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			DataGrid1.EditItemIndex = e.Item.ItemIndex;
			BindGrid();
		}

		private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			RadMaskedTextBox socialSecurityBox = (RadMaskedTextBox)e.Item.FindControl("socialSecurityTextBox");
			RadMaskedTextBox titleTextBox = (RadMaskedTextBox)e.Item.FindControl("titleTextBox");
			TextBox nameTextBox = (TextBox)e.Item.FindControl("nameTextBox");
			RadDateInput birthdayPicker = (RadDateInput)e.Item.FindControl("birthdayPicker");

			DataRow[] rows = DataSource.Select("ID=" + DataGrid1.DataKeys[e.Item.ItemIndex]);
			if (rows != null && rows.Length > 0)
			{
				rows[0]["SocialSecurity"] = socialSecurityBox.TextWithLiterals;
				rows[0]["Title"] = titleTextBox.TextWithLiterals;
				rows[0]["Name"] = nameTextBox.Text;
				rows[0]["Birthday"] = birthdayPicker.SelectedDate;
				DataGrid1.EditItemIndex = -1;
				BindGrid();
			}
		}

		private void DataGrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			DataGrid1.EditItemIndex = -1;
			BindGrid();            
		}

		private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
		{
		
		}

	}
}

⌨️ 快捷键说明

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