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

📄 defaultcs.aspx.cs

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

namespace Telerik.ComboboxExamplesCS.ComboInGrid
{
	/// <summary>
	/// Summary description for _Default.
	/// </summary>
	public class DefaultCS: XhtmlPage
	{
		protected System.Web.UI.WebControls.DataGrid DataGrid1;	
		protected Telerik.WebControls.RadComboBox RadComboBox1;
		protected Telerik.WebControls.RadComboBox RadComboBox2;
		
		private DataTable GetCachedCustomers()
		{			
			DataTable dt = (DataTable) Cache["Customers"];
			if (dt == null)
			{
				dt = new DataTable();
				string mdbPath = Server.MapPath("~/Combobox/Data/NWind.mdb"); 
				OleDbConnection dbCon = new OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + mdbPath); 
				dbCon.Open();

				OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * From Customers", dbCon);				
				adapter.Fill(dt);
				dbCon.Close();

				Cache["Customers"] = dt;
			}

			return dt;
		}

		private void BindGrid()
		{
			DataGrid1.DataSource = GetCachedCustomers();
			DataGrid1.DataBind();
		}

		private void Page_Load(object sender, System.EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				BindGrid();				
			}
		}
		

		#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.DataGrid1.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid1_PageIndexChanged);
			this.DataGrid1.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_CancelCommand);
			this.DataGrid1.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_EditCommand);
			this.DataGrid1.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_UpdateCommand);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion		

		
		public DataTable LoadCompanyNames()
		{			
			return GetCachedCustomers();
		}

		public DataTable LoadContactNames()
		{			
			return GetCachedCustomers();
		}

		public void UpdateDataBaseEntry(string id, string companyName, string contactName)
		{
			DataTable dt = GetCachedCustomers();
			DataRow [] rows = dt.Select(String.Format("CustomerID='{0}'", id));

			rows[0]["CompanyName"] = companyName;
			rows[0]["ContactName"] = contactName;

			Cache["Customers"] = dt;
			BindGrid();
		}

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

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

		private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{		
			RadComboBox combo1 = (RadComboBox) e.Item.FindControl("RadComboBox1");
			RadComboBox combo2 = (RadComboBox) e.Item.FindControl("RadComboBox2");			
			
			UpdateDataBaseEntry(e.Item.Cells[0].Text, combo1.Text, combo2.Text);

			DataGrid1.EditItemIndex = -1;
			BindGrid();
		}

		private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
		{
			DataGrid1.EditItemIndex = -1;
			DataGrid1.CurrentPageIndex = e.NewPageIndex;
			BindGrid();
		}
	}
}

⌨️ 快捷键说明

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