菜鸟问个DropDownList问题
想实现易做图或以上的联动 但是现在做到2级后就不行了 第易做图动不了呀 请帮忙看看public void BindDropDownList()
{
string conStr = ConfigurationSettings.AppSettings["connString"];
SqlConnection myConnection = new SqlConnection(conStr);
SqlCommand Comm1=new SqlCommand("select * from Shops ",myConnection);
myConnection.Open();//取得第一级DropDownList
SqlDataReader Dr1=Comm1.ExecuteReader();
while(Dr1.Read())
{
db.Items.Add( new ListItem(Dr1["ShopName"].ToString()));
}
myConnection.Close();
myConnection.Open();//测试
SqlCommand cmdShop = new SqlCommand("select * from BasicInformation where ShopName='" + this.db.SelectedValue + "'", myConnection);
SqlDataReader sdrShop = cmdShop.ExecuteReader();
this.Layout.DataSource = sdrShop;
this.Layout.DataTextField = "Schedule";
this.Layout.DataBind();
sdrShop.Close();
myConnection.Close();
}
private void db_SelectedIndexChanged(object sender, System.EventArgs e)
{//取得第二级DropDownList
string conStr = ConfigurationSettings.AppSettings["connString"];
SqlConnection myConnection = new SqlConnection(conStr);
myConnection.Open();
SqlCommand cmdLy = new SqlCommand("select * from BasicInformation where ShopName='" + this.db.SelectedValue + "'", myConnection);
SqlDataReader sdrLy = cmdLy.ExecuteReader();
this.Layout.DataSource = sdrLy;
this.Layout.DataTextField = "Schedule";
this.Layout.DataBind();
sdrLy.Close();
myConnection.Close();
}
private void Layout_SelectedIndexChanged(object sender, System.EventArgs e)
{//取得第易做图DropDownList
string conStr = ConfigurationSettings.AppSettings["connString"];
SqlConnection myConnection = new SqlConnection(conStr);
myConnection.Open();
SqlCommand cmdGift = new SqlCommand("select * from Gift where LayoutName='" + this.Layout.SelectedValue + "'", myConnection);
SqlDataReader sGift = cmdGift.ExecuteReader();
this.GiftL.DataSource = sGift;
this.GiftL.DataTextField = "GiftSale";
this.GiftL.DataBind();
sGift.Close();
myConnection.Close();
} --------------------编程问答-------------------- 你的易做图联动是如何个动法没看明白,
第二级的动是根据第一级,那第易做图的动是根据第易做图动的,还是根据第一,第二一起联动的
这是我项目中用到的一个例子,
--------------------编程问答-------------------- 第易做图我想根据第1级和第2级动的 如果不好实现的话根据第2级动也可以
public void bindOrg() //分公司 (首选加载时所要做的事情是加载第一级,并给初始选值)
{
DataSet ds = bi.GetBase_Organize(10000000);
drpOrg.DataSource = ds;
drpOrg.DataTextField = "OrgName";
drpOrg.DataValueField = "Org_NO";
drpOrg.DataBind();
drpOrg.Items[0].Selected = true; //给定第一项为选中状态
_fatherPath = drpOrg.SelectedValue.ToString(); //默认取得选中的Value
ViewState["fatherPath"] = _fatherPath; //保存在viewstate中进行页面方法间的传递
bindOrgDev();
BindOrgEmp();
}
public void bindOrgDev() //部门
{
drpOrgDev.Items.Clear();
drpOrgDev.Items.Insert(0, (new ListItem("所有部门", "")));
drpOrgDev.DataSource = bi.GetBase_Organize_FahterPath(int.Parse(_fatherPath));
drpOrgDev.DataTextField = "OrgName";
drpOrgDev.DataValueField = "Org_NO";
drpOrgDev.DataBind();
}
public void BindOrgEmp() //员工
{
drpEmp.Items.Clear();
drpEmp.Items.Insert(0, (new ListItem("所有员工", "")));
_fatherPath = Convert.ToString(ViewState["fatherPath"]);
BLL.BASE.Base_Employee bi = new BLL.BASE.Base_Employee();
drpEmp.DataSource = bi.GetAllBase_Employee(_fatherPath, _fatherID);
drpEmp.DataTextField = "name";
drpEmp.DataValueField = "emp_no";
drpEmp.DataBind();
}
protected void drpOrg_SelectedIndexChanged(object sender, EventArgs e) //第一级变动
{
flag = false;
_fatherPath = drpOrg.SelectedValue.ToString();
ViewState["fatherPath"] = _fatherPath;
bindOrgDev();
BindOrgEmp();
}
protected void drpOrgDev_SelectedIndexChanged(object sender, EventArgs e) //第二级变动
{
flag = true;
_fatherPath = Convert.ToString(ViewState["fatherPath"]);
_fatherID = drpOrgDev.SelectedValue.ToString();
BindOrgEmp();
}
补充:.NET技术 , ASP.NET