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

📄 defaultcs.aspx.cs

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

namespace Telerik.CallbackExamplesCSharp.Controls.ListBox
{
	/// <summary>
	/// Summary description for _Default.
	/// </summary>
	public class DefaultCS: XhtmlPage
	{
		protected Telerik.WebControls.CallbackListBox lbContinents;
		protected Telerik.WebControls.CallbackListBox lbCountries;
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.Label Label2;
		protected System.Web.UI.WebControls.Label Label3;
		protected System.Web.UI.WebControls.Label label11;
		protected System.Web.UI.WebControls.Label statusLabel;
		protected Telerik.WebControls.CallbackListBox lbTowns;

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

		#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.lbContinents.SelectedIndexChanged += new System.EventHandler(this.CallbackDropDownList1_SelectedIndexChanged);
			this.lbCountries.SelectedIndexChanged += new System.EventHandler(this.CallbackDropDownList2_SelectedIndexChanged);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void LoadContinents()
		{
			string path = Server.MapPath("~/Callback/Data/Countries.mdb");
			OleDbConnection dbCon = new OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path); 
			dbCon.Open();

			OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM Continents", dbCon); 
			DataTable dt = new DataTable();
			adapter.Fill(dt);                                    
			dbCon.Close();

			lbContinents.DataTextField = "Name";
			lbContinents.DataValueField = "ID";
			lbContinents.DataSource = dt;
			lbContinents.DataBind();                                    			

			if (lbContinents.SelectedIndex == -1)
			{
				lbContinents.SelectedIndex = 0;
				LoadCountries(lbContinents.Items[0].Value);
			}
		}

		private void LoadCountries(string continentID)
		{
			string path = Server.MapPath("~/Callback/Data/Countries.mdb");
			OleDbConnection dbCon = new OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path); 
			dbCon.Open();

			OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM Countries WHERE ContinentID=" + continentID + "", dbCon); 
			DataTable dt = new DataTable();
			adapter.Fill(dt);
			dbCon.Close();

			lbCountries.DataTextField = "Name";
			lbCountries.DataValueField = "ID";
			lbCountries.DataSource = dt;
			lbCountries.DataBind();		
						
			lbCountries.SelectedIndex = 0;
			LoadCities(lbCountries.Items[0].Value);
			
			
		}

		private void LoadCities(string countryID)
		{
			string path = Server.MapPath("~/Callback/Data/Countries.mdb");
			OleDbConnection dbCon = new OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path); 
			dbCon.Open();

			OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM Cities WHERE CountryID=" + countryID, dbCon); 
			DataTable dt = new DataTable();
			adapter.Fill(dt);
			dbCon.Close();

			lbTowns.DataTextField = "Name";
			lbTowns.DataValueField = "ID";
			lbTowns.DataSource = dt;
			lbTowns.DataBind();			

			if (lbTowns.SelectedIndex == -1)
			{
				lbTowns.SelectedIndex = 0;
			}
		}

		private void CallbackDropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			LoadCountries(lbContinents.SelectedItem.Value);			
		}

		private void CallbackDropDownList2_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			LoadCities(lbCountries.SelectedItem.Value);
		}
		


	}
}

⌨️ 快捷键说明

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