两个dropdownlist 一个为ddldeptID 显示部门信息,一个为ddlPostId 显示职位信息。想实现两个dropdownlist 的联动。
当选择ddldeptID 的相应选项时,ddlPostId的显示内容发生改变。已经从数据库里查出信息无误,ddldeptID,ddlPostId的内容已在Page_load中绑定。并在selectedindexchanged 事件中编程。ddldeptID 的autoPostbace已设为true 。可是ddlpostID 中的内容。总是显示第一次查处的结果。请各位高人指点一下。不胜感激。部分源码如下:
//部门与职位下拉列表的绑定方法
private static void DeptAndPostBind(DropDownList deptbind, DropDownList postbind)
{
deptbind.DataSource = oper.GetDeptList();
deptbind.DataTextField = "TREEName";
deptbind.DataValueField = "deptid";
deptbind.DataBind();
int deptid = int.Parse(deptbind.SelectedValue);
postbind.DataSource = oper.GetPostList(deptid);
postbind.DataTextField = "treename";
postbind.DataValueField = "postid";
postbind.DataBind();
postbind.Items.Insert(0, new ListItem("-------请选择-------", "0")); }
//page_load方法
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DeptAndPostBind(ddlNewEmpDeptId ,ddlNewEmpPosition);
}
}
//职位列表的数据绑定
private static void PositionDataBind(DropDownList post,int deptid)
{
post.DataSource = oper.GetPostList(deptid);
post.DataTextField = "treename";
post.DataValueField = "postid";
post.DataBind();
post.Items.Insert(0, new ListItem("-------请选择-------", "0"));
}
//职位下拉列表的数据绑定
protected void ddlNewEmpPosition_SelectedIndexChanged(object sender, EventArgs e)
{
int deptid = int.Parse(ddlNewEmpDeptId .SelectedValue);
PositionDataBind(ddlNewEmpPosition ,deptid);
}
当选择ddldeptID 的相应选项时,ddlPostId的显示内容发生改变。已经从数据库里查出信息无误,ddldeptID,ddlPostId的内容已在Page_load中绑定。并在selectedindexchanged 事件中编程。ddldeptID 的autoPostbace已设为true 。可是ddlpostID 中的内容。总是显示第一次查处的结果。请各位高人指点一下。不胜感激。部分源码如下:
//部门与职位下拉列表的绑定方法
private static void DeptAndPostBind(DropDownList deptbind, DropDownList postbind)
{
deptbind.DataSource = oper.GetDeptList();
deptbind.DataTextField = "TREEName";
deptbind.DataValueField = "deptid";
deptbind.DataBind();
int deptid = int.Parse(deptbind.SelectedValue);
postbind.DataSource = oper.GetPostList(deptid);
postbind.DataTextField = "treename";
postbind.DataValueField = "postid";
postbind.DataBind();
postbind.Items.Insert(0, new ListItem("-------请选择-------", "0")); }
//page_load方法
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DeptAndPostBind(ddlNewEmpDeptId ,ddlNewEmpPosition);
}
}
//职位列表的数据绑定
private static void PositionDataBind(DropDownList post,int deptid)
{
post.DataSource = oper.GetPostList(deptid);
post.DataTextField = "treename";
post.DataValueField = "postid";
post.DataBind();
post.Items.Insert(0, new ListItem("-------请选择-------", "0"));
}
//职位下拉列表的数据绑定
protected void ddlNewEmpPosition_SelectedIndexChanged(object sender, EventArgs e)
{
int deptid = int.Parse(ddlNewEmpDeptId .SelectedValue);
PositionDataBind(ddlNewEmpPosition ,deptid);
}
你代码逻辑好像有问题