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

📄 itemdatabing.aspx.cs

📁 ASP.NET的一些开发实例,有论坛管理系统等
💻 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;

namespace aspnet.chapter11
{
	/// <summary>
	/// ItemDataBing 的摘要说明。
	/// </summary>
	public class ItemDataBing : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.DropDownList DDLArray;
		protected System.Web.UI.WebControls.DropDownList DDLDataView;
		protected System.Web.UI.WebControls.DropDownList DDLHash;
		protected System.Web.UI.WebControls.DropDownList DDLDR;

		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			if(!this.Page.IsPostBack)
			{
				DDLArrayDataBind();
				DDLHashtableDataBind();
				DDLDVDataBind();
				DDLDRDataBind();
			}
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion
		private void DDLArrayDataBind()
		{
			//添加数据
			ArrayList al=new ArrayList();
			al.Add("北京");
			al.Add("上海");
			al.Add("广州");
			//绑定数据
			this.DDLArray.DataSource=al;
			this.DDLArray.DataBind();
		}
		private void DDLHashtableDataBind()
		{
			//添加数据
			Hashtable ht=new Hashtable();
			ht.Add(2,"北京");
			ht.Add(1,"上海");
			ht.Add(0,"广州");
			//绑定数据
			this.DDLHash.DataSource=ht.Values;
			this.DDLHash.DataBind();
		}
		private void DDLDVDataBind()
		{
			//添加数据
			DataTable dt=new DataTable();
			dt.Columns.Add(new DataColumn("city",typeof(String)));
			string[] ss={"北京","上海","广州"};
			foreach(string s in ss)
			{
				DataRow dr=dt.NewRow();
				dr[0]=s;
				dt.Rows.Add(dr);
			}
			//绑定数据
			this.DDLDataView.DataSource=new DataView(dt);
			this.DDLDataView.DataTextField="city";
			this.DDLDataView.DataBind();
		}

		private void DDLDRDataBind()
		{
			//绑定数据
			string sConn=string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}",@"C:\Inetpub\wwwroot\aspnet\chapter11\DataReader.mdb");
			System.Data.OleDb.OleDbConnection oleConn=new System.Data.OleDb.OleDbConnection(sConn);
			string sql="select * from cityinfo";
			System.Data.OleDb.OleDbCommand cmd=new System.Data.OleDb.OleDbCommand(sql,oleConn);
			oleConn.Open();
			System.Data.OleDb.OleDbDataReader dr=cmd.ExecuteReader();
			this.DDLDR.DataSource=dr;
			this.DDLDR.DataTextField="city";
			this.DDLDR.DataBind();
			oleConn.Close();
		}
	}
}

⌨️ 快捷键说明

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