62,046
社区成员
发帖
与我相关
我的任务
分享
我的dropdownlist在页面初始化的时候
protected void Page_Load(object sender, EventArgs e)
{
AM_Department.Items.Add("请选择部门");
AM_Department.Items[0].Value = "0";
AM_Name.Items.Add("请选择姓名");
AM_Name.Items[0].Value = "0";
}
给他加的是这个 后面的内容是在这个基础上追加上去的 如果DropDownList1的AutoPostBack必须为true的话那他每选择一次 dropdownlist的内容就会再添加一次页面初始化的数据
我的部门下拉列表现在好了 我想在选择其中一个部门后 第二个下拉列表中显示出该部门下所有员工姓名,第二个下拉列表值绑定员工编号
就是2级级联
protected void AM_Department_SelectedIndexChanged(object sender, EventArgs e)
{
string dname = AM_Department.SelectedValue;
ListItem employees = new ListItem();
employees=Bll_AttendanceM.GetAllEmployeeName(dname); ////我现在这个转换也出错了 Bll_AttendanceM.GetAllEmployeeName(dname);这个返回的是LIST <BLL_Employees> 转换List或Listitem出错 绑定到第二个dropdownlist 不知道怎么让第二个下拉列表显示字段是员工姓名 值字段为员工编号
AM_Name.DataSource = employees;
AM_Name.DataBind();
}
在部门下拉列表改变时 就把该部门的员工列表查了出来返回员工对象集合 但是怎么样才能 让第二个下拉列表显示字段是员工姓名 值字段为员工编号
请教高手
我的dropdownlist在页面初始化的时候
protected void Page_Load(object sender, EventArgs e)
{
AM_Department.Items.Add("请选择部门");
AM_Department.Items[0].Value = "0";
AM_Name.Items.Add("请选择姓名");
AM_Name.Items[0].Value = "0";
}
给他加的是这个 后面的内容是在这个基础上追加上去的 如果DropDownList1的AutoPostBack必须为true的话那他每选择一次 dropdownlist的内容就会再添加一次页面初始化的数据
我的部门下拉列表现在好了 我想在选择其中一个部门后 第二个下拉列表中显示出该部门下所有员工姓名,第二个下拉列表值绑定员工编号
就是2级级联
protected void AM_Department_SelectedIndexChanged(object sender, EventArgs e)
{
string dname = AM_Department.SelectedValue;
ListItem employees = new ListItem();
employees=Bll_AttendanceM.GetAllEmployeeName(dname); ////1
AM_Name.DataSource = employees;
AM_Name.DataBind();
}
在部门下拉列表改变时 就把该部门的员工列表查了出来返回员工对象集合 但是怎么样才能 让第二个下拉列表显示字段是员工姓名 值字段为员工编号
List <Bll_Employees> employees = new List <Bll_Employees>();
string dname = AM_Department.SelectedValue;
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
//获得部门编号
string id = this.DropDownList1.SelectedValue;
//根据部门便好取出人员名单
string sqlstr = "select empid,emp from employee";
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("0", "请选择姓名");
SqlDataReader dr = SqlHelper.ExecuteReader(DataBase.ConStr, CommandType.Text, sqlstr, null);
while (dr.Read())
{
dic.Add(dr[0].ToString(), dr[1].ToString()); /////1
}
//人员下拉菜单的数据绑定
this.DropDownList2.DataSource = dic;
this.DropDownList2.DataTextField = "value";
this.DropDownList2.DataValueField = "key";
this.DropDownList2.DataBind();
}
//部门的下拉菜单的绑定
//DropDownList1的AutoPostBack必须为true
public void BindData()
{
//取数据的sql语句id:部门编号,name:部门名称
string sqlstr = "select id,name from department";
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("0", "选择部门");
SqlDataReader dr = SqlHelper.ExecuteReader(DataBase.ConStr, CommandType.Text, sqlstr, null);
while (dr.Read())
{
dic.Add(dr[0].ToString(), dr[1].ToString);
}
this.DropDownList1.DataSource = dic;
this.DropDownList1.DataTextField = "value";
this.DropDownList1.DataValueField = "key";
this.DropDownList1.DataBind();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
//获得部门编号
string id = this.DropDownList1.SelectedValue;
//根据部门便好取出人员名单
string sqlstr = "select empid,emp from employee";
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("0", "请选择姓名");
SqlDataReader dr = SqlHelper.ExecuteReader(DataBase.ConStr, CommandType.Text, sqlstr, null);
while (dr.Read())
{
dic.Add(dr[0].ToString(), dr[1].ToString());
}
//人员下拉菜单的数据绑定
this.DropDownList2.DataSource = dic;
this.DropDownList2.DataTextField = "value";
this.DropDownList2.DataValueField = "key";
this.DropDownList2.DataBind();
}
//部门的下拉菜单的绑定
//DropDownList1的AutoPostBack必须为true
public void BindData()
{
//取数据的sql语句id:部门编号,name:部门名称
string sqlstr = "select id,name from department";
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("0", "选择部门");
SqlDataReader dr = SqlHelper.ExecuteReader(DataBase.ConStr, CommandType.Text, sqlstr, null);
while (dr.Read())
{
dic.Add(dr[0].ToString(), dr[1].ToString);
}
this.DropDownList1.DataSource = dic;
this.DropDownList1.DataTextField = "value";
this.DropDownList1.DataValueField = "key";
this.DropDownList1.DataBind();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
//获得部门编号
string id = this.DropDownList1.SelectedValue;
//根据部门便好取出人员名单
string sqlstr = "select empid,emp from employee";
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("0", "请选择姓名");
SqlDataReader dr = SqlHelper.ExecuteReader(DataBase.ConStr, CommandType.Text, sqlstr, null);
while (dr.Read())
{
dic.Add(dr[0].ToString(), dr[1].ToString());
}
//人员下拉菜单的数据绑定
this.DropDownList2.DataSource = dic;
this.DropDownList2.DataTextField = "value";
this.DropDownList2.DataValueField = "key";
this.DropDownList2.DataBind();
}