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

📄 defaultcs.aspx.cs

📁 Telerik是很大的第三方软件制造商
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
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;
using Telerik.WebControls.CallbackControls;

namespace Telerik.CallbackExamplesCSharp.Controls.Label
{
	/// <summary>
	/// Summary description for _Default.
	/// </summary>
	public class DefaultCS: XhtmlPage
	{
		protected System.Web.UI.WebControls.Panel Panel1;
		protected System.Web.UI.WebControls.Label lblDescription;
		protected System.Web.UI.WebControls.ListBox ListBox1;
		protected CallbackLabel CallbackLabel1;
		protected Telerik.WebControls.CallbackLabel lblBook1;		
		protected Telerik.WebControls.CallbackLabel lblBook2;
		protected Telerik.WebControls.CallbackLabel lblBook3;
		protected Telerik.WebControls.CallbackLabel lblBook4;
		protected System.Web.UI.WebControls.Label label11;
		protected System.Web.UI.WebControls.Label statusLabel;
		protected System.Web.UI.HtmlControls.HtmlImage Img1;
		protected Telerik.WebControls.LoadingPanel LoadingPanel1;
		protected Telerik.WebControls.CallbackLabel lblBook5;
		
		private void Page_Load(object sender, System.EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				LoadInitialData();
			
			}			
		}

		#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.lblBook1.MouseOver += new Telerik.WebControls.CallbackControls.MouseEventHandler(this.CallbackLabel1_MouseOver);
			//this.lblBook1.MouseDblClick += new Telerik.WebControls.CallbackControls.MouseEventHandler(this.lblBook1_MouseDblClick);
			this.lblBook1.MouseClick += new Telerik.WebControls.CallbackControls.MouseEventHandler(this.lblBook1_MouseClick);
			
			this.lblBook2.MouseOver += new Telerik.WebControls.CallbackControls.MouseEventHandler(this.CallbackLabel1_MouseOver);
			//this.lblBook2.MouseDblClick += new Telerik.WebControls.CallbackControls.MouseEventHandler(this.lblBook1_MouseDblClick);
			this.lblBook2.MouseClick += new Telerik.WebControls.CallbackControls.MouseEventHandler(this.lblBook1_MouseClick);
			
			this.lblBook3.MouseOver += new Telerik.WebControls.CallbackControls.MouseEventHandler(this.CallbackLabel1_MouseOver);
			//this.lblBook3.MouseDblClick += new Telerik.WebControls.CallbackControls.MouseEventHandler(this.lblBook1_MouseDblClick);
			this.lblBook3.MouseClick += new Telerik.WebControls.CallbackControls.MouseEventHandler(this.lblBook1_MouseClick);
			
			this.lblBook4.MouseOver += new Telerik.WebControls.CallbackControls.MouseEventHandler(this.CallbackLabel1_MouseOver);
			//this.lblBook4.MouseDblClick += new Telerik.WebControls.CallbackControls.MouseEventHandler(this.lblBook1_MouseDblClick);
			this.lblBook4.MouseClick += new Telerik.WebControls.CallbackControls.MouseEventHandler(this.lblBook1_MouseClick);
			
			this.lblBook5.MouseOver += new Telerik.WebControls.CallbackControls.MouseEventHandler(this.CallbackLabel1_MouseOver);
			//this.lblBook5.MouseDblClick += new Telerik.WebControls.CallbackControls.MouseEventHandler(this.lblBook1_MouseDblClick);
			this.lblBook5.MouseClick += new Telerik.WebControls.CallbackControls.MouseEventHandler(this.lblBook1_MouseClick);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void LoadInitialData()		
		{
			string path = Server.MapPath("~/Callback/data/books.mdb");
			OleDbConnection dbCon = new OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path); 
			dbCon.Open();
			OleDbCommand command = new OleDbCommand("SELECT name FROM books", dbCon);
			OleDbDataReader reader = command.ExecuteReader();									
			reader.Read();
			lblBook1.Text = (string) reader.GetValue(0);
			reader.Read();
			lblBook2.Text = (string) reader.GetValue(0);
			reader.Read();
			lblBook3.Text = (string) reader.GetValue(0);
			reader.Read();
			lblBook4.Text = (string) reader.GetValue(0);
			reader.Read();
			lblBook5.Text = (string) reader.GetValue(0);

			dbCon.Close();
		}

		private string GetBookSummary(int bookID)
		{
			string path = Server.MapPath("~/Callback/data/books.mdb");
			OleDbConnection dbCon = new OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path); 
			dbCon.Open();
			OleDbCommand command = new OleDbCommand("SELECT summary FROM books WHERE id = " + bookID.ToString(), dbCon);
			string summary = (string) command.ExecuteScalar();
			dbCon.Close();
			return summary;
		}

		private void CallbackLabel1_MouseOver(object sender, MouseEventArgs args)
		{
			CallbackLabel label = (CallbackLabel) sender;
			switch (label.ID)
			{
				case "lblBook1":
				{
					lblDescription.Text = GetBookSummary(1);
					break;
				}
				case "lblBook2":
				{
					lblDescription.Text = GetBookSummary(2);
					break;
				}
				case "lblBook3":
				{
					lblDescription.Text = GetBookSummary(3);
					break;
				}
				case "lblBook4":
				{
					lblDescription.Text = GetBookSummary(4);
					break;
				}
				case "lblBook5":
				{
					lblDescription.Text = GetBookSummary(5);
					break;
				}
			}								
		}

		private void lblBook1_MouseClick(object sender, Telerik.WebControls.CallbackControls.MouseEventArgs args)
		{
			CallbackLabel label = (CallbackLabel) sender;
			ListItem item = ListBox1.Items.FindByText(label.Text);
			if (item == null)
			{
				ListBox1.Items.Add( label.Text );
			}			
			else
			{
				label.ResponseScript = string.Format("alert('{0}')", "This book is already added to cart.");
			}		
		}		


	}
}

⌨️ 快捷键说明

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