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

📄 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.WebControls;

namespace Telerik.CallbackExamplesCSharp.Callback.Examples.Demos.Contacts
{
	/// <summary>
	/// Summary description for _Default.
	/// </summary>
	public class _Default : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox nameBox;
		protected System.Web.UI.WebControls.TextBox emailBox;
		protected CallbackRadioButton personalRadioButton;
		protected CallbackRadioButton workRadioButton;
		protected System.Web.UI.WebControls.DropDownList groupDropDown;
		protected System.Web.UI.WebControls.DropDownList avatarDropDown;
		protected CallbackDropDownList contactsFilterDropDown;
		protected CallbackImageButton saveButton;
		protected CallbackImageButton cancelButton;
		protected Telerik.WebControls.LoadingPanel LoadingPanel1;
		protected System.Web.UI.HtmlControls.HtmlImage Img1;
		protected Telerik.WebControls.LoadingPanel bigLoadingPanel;
		protected Telerik.WebControls.LoadingPanel progressBarLoadingPanel;
		protected System.Web.UI.HtmlControls.HtmlImage Img2;
		protected System.Web.UI.WebControls.Panel leftPanel;
		protected System.Web.UI.WebControls.DataGrid contactsGrid;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				dataTable = new DataTable();

				dataTable.Columns.Add("Name", typeof(string));
				dataTable.Columns.Add("Email", typeof(string));
				dataTable.Columns.Add("Type", typeof(string));
 
				dataTable.Rows.Add(new object[] {"Joe Satriani", "joe@domain.com", "Personal"});
				dataTable.Rows.Add(new object[] {"Steve Vai", "steve@domain.com", "Personal"});
				dataTable.Rows.Add(new object[] {"Tony Macalpine", "tony@domain.com", "Personal"});
				dataTable.Rows.Add(new object[] {"Brett Garsed", "brett@domain.com", "Work"});
				dataTable.Rows.Add(new object[] {"Rey Mysterio", "ray@wwe.com", "Work"});
				dataTable.Rows.Add(new object[] {"Yngwie Malmsteen", "yngwie@domain.com", "Work"});

				BindGrid();
				BindGroupsAndAvatars();

			}
		}

		private DataTable dataTable
		{
			get
			{
				return (DataTable) ViewState["table"];
			}
			set
			{
				ViewState["table"] = value;
			}
		}

		private DataView dataView
		{
			get
			{
				DataView source = new DataView(dataTable);
				ListItem selected = contactsFilterDropDown.Items[contactsFilterDropDown.SelectedIndex];
				if (selected.Value != "All")
				{
					source.RowFilter = string.Format("Type = '{0}'", selected.Value);
				}

				return source;
			}
		}

		#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.contactsGrid.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.contactsGrid_EditCommand);
			this.contactsGrid.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.contactsGrid_DeleteCommand);
			this.saveButton.Click += new ImageClickEventHandler(this.saveButton_Click);
			this.cancelButton.Click += new ImageClickEventHandler(this.cancelButton_Click);
			this.contactsFilterDropDown.SelectedIndexChanged += new EventHandler(this.contactsFilterDropDown_SelectedIndexChanged);
			this.personalRadioButton.CheckedChanged += new EventHandler(this.personalRadioButton_CheckedChanged);
			this.workRadioButton.CheckedChanged += new EventHandler(this.workRadioButton_CheckedChanged);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void contactsFilterDropDown_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			DataView source = new DataView(dataTable);
			ListItem selected = contactsFilterDropDown.Items[contactsFilterDropDown.SelectedIndex];
			if (selected.Value != "All")
			{
				source.RowFilter = string.Format("Type = '{0}'", selected.Value);
			}

			BindGrid();
		}

		private void BindGrid()
		{
			contactsGrid.DataSource = dataView;
			contactsGrid.DataBind();
		}

		private void personalRadioButton_CheckedChanged(object sender, System.EventArgs e)
		{
			BindGroupsAndAvatars();
		}

		private void BindGroupsAndAvatars()
		{
			string[] personalGroups = new string[]{"Family", "Friends"};
			string[] workGroups = new string[]{"Sales", "Engineering"};
			string[] personalAvatars = new string[]{"Heart", "Smile"};
			string[] workAvatars = new string[]{"VIP", "Local", "Foreign"};
	
	
			if (personalRadioButton.Checked == true)
			{
				BindDropDown(groupDropDown, personalGroups);
				BindDropDown(avatarDropDown, personalAvatars);
			}
			else
			{
				BindDropDown(groupDropDown, workGroups);
				BindDropDown(avatarDropDown, workAvatars);
			}
		}

		private void BindDropDown(DropDownList dropDown, string[] personalGroups)
		{
			dropDown.DataSource = personalGroups;
			dropDown.DataBind();
		}

		private void workRadioButton_CheckedChanged(object sender, System.EventArgs e)
		{
			BindGroupsAndAvatars();
		}

		private void cancelButton_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			ClearFields();
		}

		private void ClearFields()
		{
			nameBox.Text = "";
			emailBox.Text = "";
		}

		private void saveButton_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			string type = "Personal";
			if (workRadioButton.Checked == true)
				type = "Work";

			string name = nameBox.Text;
			string email = emailBox.Text;

			if (name == string.Empty)
				return;

			DataRow item = FindRow(name, email);
			if (item == null)
			{
				dataTable.Rows.Add(new object[]{name, email, type});
			}
			else
			{
				item["Name"] = name;
				item["Email"] = email;
				item["Type"] = type;
			}
			BindGrid();

			ClearFields();
		}

		private DataRow FindRow(string name, string email)
		{
			DataRow[] rows = dataTable.Select(string.Format("Name = '{0}' OR Email = '{1}'", name, email));
			if (rows.Length > 0)
				return rows[0];
			else
				return null;
		}

		private void contactsGrid_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			DataRow row = GetRow(e);
			row.Delete();
			
			BindGrid();
		}

		private DataRow GetRow(DataGridCommandEventArgs e)
		{
			int index = e.Item.DataSetIndex;
			return dataView[index].Row;
		}

		private void contactsGrid_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			DataRow item = GetRow(e);
			nameBox.Text = (string) item["Name"];
			emailBox.Text = (string) item["Email"];
			if ((string) item["Type"] == "Personal")
			{
				personalRadioButton.Checked = true;
			}
			else
			{
				workRadioButton.Checked = true;
			}
			BindGroupsAndAvatars();
		}
	}
}

⌨️ 快捷键说明

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