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 System.Data.SqlClient;
using Ajax;
namespace NetTest.ListBoxTest
{
/// <summary>
/// ListBoxToListBox 的摘要说明。
/// </summary>
public class ListBoxToListBox : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList ddlDept;
protected System.Web.UI.WebControls.Button btnSubmit;
protected System.Web.UI.WebControls.ListBox listEmployees;
protected System.Web.UI.WebControls.ListBox listNewEmp;
protected System.Web.UI.WebControls.TextBox txtEmpID;
private string strConn=System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"].ToString();
private void Page_Load(object sender, System.EventArgs e)
{
Ajax.Utility.RegisterTypeForAjax(typeof(NetTest.ListBoxTest.AjaxMethod));
if(!IsPostBack)
{
GetDepartment();
GetEmployees();
btnSubmit.Attributes.Add("onclick","GetData();");
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btnSubmit.Click += new System.EventHandler(this.btnSubmit_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
#region 得到部门
private void GetDepartment()
{
SqlConnection Conn=new SqlConnection(strConn);
SqlCommand Cmd=new SqlCommand("Select * from Department",Conn);
SqlDataAdapter da=new SqlDataAdapter();
da.SelectCommand=Cmd;
DataSet ds=new DataSet();
Conn.Open();
da.Fill(ds);
Conn.Close();
ddlDept.DataSource=ds.Tables[0].DefaultView;
ddlDept.DataTextField="Name";
ddlDept.DataValueField="DeptID";
ddlDept.DataBind();
ddlDept.Attributes.Add("onChange","BindListEmp()");
}
#endregion
#region 得到所有的员工
private void GetEmployees()
{
SqlConnection Conn=new SqlConnection(strConn);
SqlCommand Cmd=new SqlCommand("Select * from Emp",Conn);
SqlDataAdapter da=new SqlDataAdapter();
da.SelectCommand=Cmd;
DataSet ds=new DataSet();
Conn.Open();
da.Fill(ds);
Conn.Close();
listEmployees.DataSource=ds.Tables[0].DefaultView;
listEmployees.DataTextField="EmpName";
listEmployees.DataValueField="EmpID";
listEmployees.DataBind();
}
#endregion
private void btnSubmit_Click(object sender, System.EventArgs e)
{
Response.Write(txtEmpID.Text);
}
}
}
|