Bind(); }
private void Bind() {
SqlConnection con = new
SqlConnection(ConfigurationManager.ConnectionStrings[\\
string sql = \部门编号,D_Name 部门名称,D_Tel 联系电话,D_Address 联系地址,D_Chief 负责人,D_Belong 所属部门 from [Tb_department]\
SqlDataAdapter sda = new SqlDataAdapter(sql, con); DataSet ds = new DataSet(); sda.Fill(ds, \ con.Close();
ListDepart.DataSource = ds.Tables[\ ListDepart.DataBind(); }
protected void ListDepart_PageIndexChanging(object sender, GridViewPageEventArgs e) {
ListDepart.PageIndex = e.NewPageIndex; DataBind(); } }
4、Search_Depart(查询部门信息) using System; using System.Data;
using System.Configuration; using System.Collections;
- 23 -
using System.Web;
using System.Web.Security; using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient;
public partial class WebFiles_Department_Search_Depart : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) { }
protected void brn_search_Click(object sender, EventArgs e) {
if (role.SelectedValue == \部门编号\ {
if (TxtContent.Text.Trim() == \ {
Response.Write(\部门编号不能为空!')\ } else {
string sql = \部门编号,D_Name 部门名称,D_Tel 联系电话,D_Address 联系地址,D_Chief 负责人,D_Belong 所属部门 from [Tb_department] where [D_ID]='\ user Search = new user();
SqlDataReader myreader = Search.Login(sql); List_employee.DataSource = myreader;
- 24 -
List_employee.DataBind(); } }
else if (role.SelectedValue == \部门名称\ {
if (TxtContent.Text.Trim() == \ {
Response.Write(\部门名称不能为空!')\ } else {
string sql = \部门编号,D_Name 部门名称,D_Tel 联系电话,D_Address 联系地址,D_Chief 负责人,D_Belong 所属部门 from [Tb_department] where [D_Name]='\ user Search = new user();
SqlDataReader myreader = Search.Login(sql); List_employee.DataSource = myreader; List_employee.DataBind(); } } else {
if (TxtContent.Text.Trim() == \ {
Response.Write(\负责人不能为空!')\ } else {
- 25 -
string sql = \部门编号,D_Name 部门名称,D_Tel 联系电话,D_Address 联系地址,D_Chief 负责人,D_Belong 所属部门 from [Tb_department] where [D_Chief]='\+ TxtContent.Text.Trim() + \ user Search = new user();
SqlDataReader myreader = Search.Login(sql); List_employee.DataSource = myreader; List_employee.DataBind(); } } } }
4.2系统测试
1.添加部门信息界面
图4.2.1添加部门信息
2.部门信息查询(按部门编号)界面
- 26 -