问题描述
错误提示是“ddlXCity”有一个无效SelectedValue,因为它不在项目列表中。参数名:value出问题的代码DataSetds=WebPubDB.DbHelper.Query("selectorganid,organname,organupid,schoolcitiesfromdc_organwhereorganid="+yixinUtils.GetSchoolID(openid,apid));//根据openid,apid得到学校所在地市,区县,及学校idddlCity.SelectedValue=ds.Tables[0].Rows[0][3].ToString();ddlCity_SelectedIndexChanged(this,null);ddlXCity.SelectedValue=ds.Tables[0].Rows[0][2].ToString();ddlXCity_SelectedIndexChanged(this,null);ddlSchool.SelectedValue=(ds.Tables[0].Rows[0][0].ToString());//绑定
看代码,三级dropdownlist联动//绑定地市运行上面那段代码之前,先执行下这个protectedvoidbind(){DataSetds=WebPubDB.DbHelper.Query("selectOrganID,OrganFullNamefromdc_organwhereorgantypename='地市'orderbyorganname");this.ddlCity.DataSource=ds.Tables[0];this.ddlCity.DataTextField="OrganFullName";this.ddlCity.DataValueField="OrganID";this.ddlCity.DataBind();ddlCity.Items.Add(newListItem("请选择","-1"));ddlCity.SelectedValue="-1";ddlCity_SelectedIndexChanged(this,null);}//地市改变区县跟着改变protectedvoidddlCity_SelectedIndexChanged(objectsender,EventArgse){DataSetds=WebPubDB.DbHelper.Query("selectqxno,qxnamefromdc_qxinfowhereorganupid='"+ddlCity.SelectedValue+"'orderbyqxname");ddlXCity.Items.Clear();ddlXCity.DataSource=ds.Tables[0];ddlXCity.DataTextField="qxname";ddlXCity.DataValueField="qxno";ddlXCity.DataBind();ddlXCity.Items.Add(newListItem("请选择","-1"));ddlXCity.SelectedValue="-1";ddlXCity_SelectedIndexChanged(this,null);}//区县改变学校跟着改变protectedvoidddlXCity_SelectedIndexChanged(objectsender,EventArgse){DataSetds=WebPubDB.DbHelper.Query("selectOrganID,OrganNamefromdc_organwhereorgantypename='学校'andorganupid='"+ddlXCity.SelectedValue+"'orderbyorganname");ddlSchool.Items.Clear();ddlSchool.DataSource=ds.Tables[0];ddlSchool.DataTextField="OrganName";ddlSchool.DataValueField="OrganID";ddlSchool.DataBind();ddlSchool.Items.Add(newListItem("请选择","-1"));ddlSchool.SelectedValue="-1";}
我将上面的代码改成下面这样不调用bind,和联动就没问题了DataSetds=WebPubDB.DbHelper.Query("selectorganid,organname,organupid,schoolcitiesfromdc_organwhereorganid="+yixinUtils.GetSchoolID(openid,apid));DataSetdsd=WebPubDB.DbHelper.Query("selectOrganID,OrganFullNamefromdc_organwhereorgantypename='地市'orderbyorganname");this.ddlCity.DataSource=dsd.Tables[0];this.ddlCity.DataTextField="OrganFullName";this.ddlCity.DataValueField="OrganID";this.ddlCity.DataBind();ddlCity.SelectedValue=ds.Tables[0].Rows[0][3].ToString();DataSetdsx=WebPubDB.DbHelper.Query("selectqxno,qxnamefromdc_qxinfowhereorganupid='"+ddlCity.SelectedValue+"'orderbyqxname");ddlXCity.Items.Clear();ddlXCity.DataSource=dsx.Tables[0];ddlXCity.DataTextField="qxname";ddlXCity.DataValueField="qxno";ddlXCity.DataBind();ddlXCity.SelectedValue=ds.Tables[0].Rows[0][2].ToString();DataSetdss=WebPubDB.DbHelper.Query("selectOrganID,OrganNamefromdc_organwhereorgantypename='学校'andorganupid='"+ddlXCity.SelectedValue+"'orderbyorganname");txtname.Text=yixinUtils.GetTel(openid,apid);ddlSchool.Items.Clear();ddlSchool.DataSource=dss.Tables[0];ddlSchool.DataTextField="OrganName";ddlSchool.DataValueField="OrganID";ddlSchool.DataBind();ddlSchool.SelectedValue=ds.Tables[0].Rows[0][0].ToString();
何解??
解决方案
解决方案二:
还有用dataset可视化工具查看报错。。什么情况
解决方案三:
因为第一种写法区县里没有加载地市或者由于刷新导致地市需要再区县里重新加载