1:前台jquery代码
//根据部门 获取员工姓名
function GetEmployeeName() {
var gid = $("# MdDepartment_ParentID");
var gpid = $("#HrEmployee_EmployeeName");
$("#HrEmployee_EmployeeName option").remove(); // 先删除所有项,以便重新加载
gpid.append("<option value=''>--- 请选择 ---</option>"); //默认项
$.ajax({
type: "Post",
url: "Edit.aspx/getEmployeeName",
data: "{'DepartmentID':'" + gid.val() + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
var arrayChar = data.d;
for (var index in arrayChar) {
if (typeof arrayChar[index] != 'undefined' && typeof arrayChar[index] != 'function') {
var info = arrayChar[index];
gpid.append($("<option></option>").val(info.ID).html(info.EmployeeName));
}
}
},
error: function (err) {
}
});
}
//获取员工工号
function GetWorkNumInfo() {
var gid = $("#HrEmployee_EmployeeName");
var ms = $("#HrEmployee_WorkNo");
$.ajax({
type: "Post",
url: "Edit.aspx/GetWorkNumInfo",
data: "{'ID':'" + gid.val() + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
var arrayObj = data.d.toString().split(",");
ms.val(arrayObj[0]);
},
error: function (err) {
//alert(err);
}
});
}
2:后台代码.cs
[System.Web.Services.WebMethod]
public static List<string> GetWorkNumInfo(string ID)
{
List<string> list = new List<string>();
HrEmployee bll = new HrEmployee();
HrEmployeeInfo info = bll.GetModel(ID);
if (info != null)
{
list.Add(info.WorkNo);
}
return list;
}
[System.Web.Services.WebMethod]
public static List<HrEmployeeInfo> getEmployeeName(string DepartmentID)
{
HrEmployee bll = new HrEmployee();
List<DBParameter> dbParameters = new List<DBParameter>();
dbParameters.Add(new DBParameter("@DepartmentID", DepartmentID));
List<HrEmployeeInfo> list = bll.GetList("", "DepartmentID=@DepartmentID", "", dbParameters);
return list;
}
注:HrEmployeeInfo 为实体类 希望大家能够看懂