With ASP.net control to achieve departmental and employee linkage, the reference process is as follows
Effect Chart:
Default.aspx code:
<%@ Page language= "C #" autoeventwireup= "true" codefile= "Default.aspx.cs" inherits= "_default"%> <!
DOCTYPE html>
Default.aspx.cs Code:
using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Data.SqlClient; Public partial class _default:system.web.ui.page {protected void Page_Load (object sender, EventArgs e) {if (!th Is.
IsPostBack) {SqlConnection con = dbcon.createconnection (); Con.
Open ();
Display Department SqlCommand cmd = new SqlCommand ("SELECT * from Tdepartment", con); SqlDataReader SDR = cmd.
ExecuteReader ();
This.ddlDep.DataSource = SDR;
This.ddlDep.DataTextField = "Depname";
This.ddlDep.DataValueField = "Depid";
This.ddlDep.DataBind (); Sdr.
Close (); Displays employee SqlCommand cmdemp =new SqlCommand ("SELECT * from emp where depid=" + THIS.DDLDEP.)
SelectedValue, con);
SqlDataReader sdremp = Cmdemp.executereader (); while (Sdremp.read ()) {THIS.LBOXEMP.ITEMS.ADD (new ListItem) (sdremp.getstring (1), sdremp. GetInt32 (0).
ToString ()));
} Sdremp.close (); Close connection con.
Close ();
} protected void Ddldep_selectedindexchanged (object sender, EventArgs e) {this.lBoxEmp.Items.Clear ();
SqlConnection con = dbcon.createconnection (); Con.
Open ();
SqlCommand cmdemp = new SqlCommand ("SELECT * from emp where depid=" + this.ddlDep.SelectedValue, con);
SqlDataReader sdremp = Cmdemp.executereader (); while (Sdremp.read ()) {THIS.LBOXEMP.ITEMS.ADD (new ListItem) (sdremp.getstring (1), Sdremp.getint32 (0).
ToString ()));
} sdremp.close (); Close connection con.
Close (); }
}
DBCon.cs Code
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using System.Data.SqlClient;
<summary>
///Dbcon Summary description
///</summary> public
class Dbcon
{public
Dbcon ()
{////
TODO: Add constructor logic
//
} public
static SqlConnection createconnection ()
{
SqlConnection con = new SqlConnection ("server=.; database=department;uid=sa;pwd=123456 ");
Return con.
}
}
Using the ASP.net control is simpler, but it is best not to use it in the case of a large number of users, and constant requests to the server can put a heavy burden on the server. Using jquery and AJAX implementations can have dynamic effects, the implementation process is more complex, but there is data buffering and Ajax local refresh can reduce the burden on the server, jquery implementation cascading dropdown box effect, reference this article: http://www.jb51.net/article/72366.htm
If you want to learn more, you can click the jquery dropdown box effect summary, JavaScript drop-down Box effect summary to learn.
The above is asp.net implementation of cascading Drop-down Box effect example, I hope we can apply.