问题描述
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;namespaceUserWeb{publicpartialclassWebForm1:System.Web.UI.Page{publicstring[]gradeList=newstring[]{"一年级","二年级","三年级"};publicstring[]classList1=newstring[]{"一班","二班","三班","四班"};publicstring[]classList2=newstring[]{"一班","二班","三班"};publicstring[]classList3=newstring[]{"一班","二班"};publicstring[]studentName=newstring[]{"1","2"};publicstring[]studentName1=newstring[]{"2","3"};publicstring[]studentName2=newstring[]{"4","5"};protectedvoidPage_Load(objectsender,EventArgse){//ASPxComboBoxGrade.DataSource=gradeList;//ASPxComboBoxGrade.DataBind();}protectedvoidASPxComboBoxGrade_SelectedIndexChanged(objectsender,EventArgse){//ASPxComboBoxGrade.DataSource=gradeList;//ASPxComboBoxGrade.DataBind();ASPxComboBoxGrade.Items.Clear();ASPxComboBoxGrade.Items.Add(gradeList[0]);ASPxComboBoxGrade.Items.Add(gradeList[1]);ASPxComboBoxGrade.Items.Add(gradeList[2]);stringgrade=ASPxComboBoxGrade.SelectedItem.ToString();if(grade==gradeList[0]){ASPxComboBoxClass.Items.Clear();ASPxComboBoxClass.Items.Add(classList1[0]);ASPxComboBoxClass.Items.Add(classList1[1]);ASPxComboBoxClass.Items.Add(classList1[2]);ASPxComboBoxClass.Items.Add(classList1[3]);ASPxComboBoxClass.DataSource=classList1;ASPxComboBoxClass.DataBind();}elseif(grade==gradeList[1]){ASPxComboBoxClass.Items.Add(classList2[0]);ASPxComboBoxClass.Items.Add(classList2[1]);ASPxComboBoxClass.Items.Add(classList2[2]);ASPxComboBoxClass.DataSource=classList2;ASPxComboBoxClass.DataBind();}elseif(grade==gradeList[2]){ASPxComboBoxClass.Items.Add(classList3[0]);ASPxComboBoxClass.Items.Add(classList3[1]);ASPxComboBoxClass.DataSource=classList3;ASPxComboBoxClass.DataBind();}}protectedvoidASPxComboBoxClass_SelectedIndexChanged(objectsender,EventArgse){stringclass1=ASPxComboBoxClass.SelectedItem.ToString();if(class1==gradeList[0]){ASPxComboBoxStudentName.Items.Add(classList1[0]);ASPxComboBoxStudentName.Items.Add(classList1[1]);}elseif(class1==gradeList[1]){ASPxComboBoxClass.Items.Add(classList2[0]);ASPxComboBoxClass.Items.Add(classList2[1]);}elseif(class1==gradeList[2]){ASPxComboBoxClass.Items.Add(classList2[0]);}}protectedvoidASPxComboBoxStudentName_SelectedIndexChanged(objectsender,EventArgse){}}}这是我刚学c#写的一个简单的三层级联,,,但是不知道为什么在每个combobox里都不显示数据,,求解答呀
解决方案
解决方案二:
不要沉呀,,帮帮忙呀,刚学编程,,,菜鸟一只
解决方案三:
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;namespaceUserWeb{publicpartialclassWebForm1:System.Web.UI.Page{publicstring[]gradeList=newstring[]{"一年级","二年级","三年级"};publicstring[]classList1=newstring[]{"一班","二班","三班","四班"};publicstring[]classList2=newstring[]{"一班","二班","三班"};publicstring[]classList3=newstring[]{"一班","二班"};publicstring[]studentName=newstring[]{"1","2"};publicstring[]studentName1=newstring[]{"2","3"};publicstring[]studentName2=newstring[]{"4","5"};protectedvoidPage_Load(objectsender,EventArgse){ASPxComboBoxGrade.DataSource=gradeList;ASPxComboBoxGrade.DataBind();}protectedvoidASPxComboBoxGrade_SelectedIndexChanged(objectsender,EventArgse){ASPxComboBoxGrade.Items.Clear();ASPxComboBoxGrade.Items.Add(gradeList[0]);ASPxComboBoxGrade.Items.Add(gradeList[1]);ASPxComboBoxGrade.Items.Add(gradeList[2]);stringgrade=ASPxComboBoxGrade.SelectedItem.ToString();if(grade==gradeList[0]){ASPxComboBoxClass.Items.Clear();ASPxComboBoxClass.Items.Add(classList1[0]);ASPxComboBoxClass.Items.Add(classList1[1]);ASPxComboBoxClass.Items.Add(classList1[2]);ASPxComboBoxClass.Items.Add(classList1[3]);ASPxComboBoxClass.DataSource=classList1;ASPxComboBoxClass.DataBind();}elseif(grade==gradeList[1]){ASPxComboBoxClass.Items.Clear();ASPxComboBoxClass.Items.Add(classList2[0]);ASPxComboBoxClass.Items.Add(classList2[1]);ASPxComboBoxClass.Items.Add(classList2[2]);ASPxComboBoxClass.DataSource=classList2;ASPxComboBoxClass.DataBind();}elseif(grade==gradeList[2]){ASPxComboBoxClass.Items.Clear();ASPxComboBoxClass.Items.Add(classList3[0]);ASPxComboBoxClass.Items.Add(classList3[1]);ASPxComboBoxClass.DataSource=classList3;ASPxComboBoxClass.DataBind();}}protectedvoidASPxComboBoxClass_SelectedIndexChanged(objectsender,EventArgse){stringclass1=ASPxComboBoxClass.SelectedItem.ToString();if(class1==gradeList[0]){ASPxComboBoxStudentName.Items.Clear();ASPxComboBoxStudentName.Items.Add(studentName[0]);ASPxComboBoxStudentName.Items.Add(studentName[1]);}elseif(class1==gradeList[1]){ASPxComboBoxStudentName.Items.Clear();ASPxComboBoxStudentName.Items.Add(studentName1[0]);ASPxComboBoxStudentName.Items.Add(studentName[1]);}elseif(class1==gradeList[2]){ASPxComboBoxStudentName.Items.Clear();ASPxComboBoxStudentName.Items.Add(studentName[0]);ASPxComboBoxStudentName.Items.Add(studentName[1]);}}protectedvoidASPxComboBoxStudentName_SelectedIndexChanged(objectsender,EventArgse){}}}刚才发的不对,这个事,求帮帮忙改一改呀
解决方案四:
http://blog.csdn.net/xianfajushi/article/details/5928136
解决方案五:
ASPxComboBoxGrade.Items.Clear();ASPxComboBoxGrade.Items.Add(gradeList[0]);ASPxComboBoxGrade.Items.Add(gradeList[1]);ASPxComboBoxGrade.Items.Add(gradeList[2]);这里为什么要清空他又加回来?没什么意义啊。stringgrade=ASPxComboBoxGrade.SelectedItem.Value.ToString();试试以下的SelectedItem也这样改看看。
解决方案六:
调用数据库信息三级联动示例//下拉框控件设置<asp:UpdatePanelrunat="server"><ContentTemplate><asp:DropDownListID="ddlProvince"runat="server"AutoPostBack="True"onselectedindexchanged="ddlProvince_SelectedIndexChanged"></asp:DropDownList><asp:DropDownListID="ddlCity"runat="server"AutoPostBack="true"onselectedindexchanged="ddlCity_SelectedIndexChanged"></asp:DropDownList><asp:DropDownListID="ddlArea"runat="server"></asp:DropDownList></ContentTemplate></asp:UpdatePanel>//加载数据库信息显示SqlConnectionsqlcon;stringstrCon=ConfigurationManager.AppSettings["conn"];protectedvoidPage_Load(objectsender,EventArgse){if(!IsPostBack){sqlcon=newSqlConnection(strCon);stringsqlstr="selectProvincefromtb_Province";sqlcon.Open();SqlDataAdaptermyda=newSqlDataAdapter(sqlstr,sqlcon);DataSetmyds=newDataSet();myda.Fill(myds);ddlProvince.DataSource=myds;ddlProvince.DataValueField="Province";ddlProvince.DataBind();stringstrCity="select*fromtb_CitywhereProvince='"+ddlProvince.SelectedItem.Text+"'";SqlDataAdaptermydaCity=newSqlDataAdapter(strCity,sqlcon);DataSetmydsCity=newDataSet();mydaCity.Fill(mydsCity);ddlCity.DataSource=mydsCity;ddlCity.DataValueField="City";ddlCity.DataBind();stringstrArea="select*fromtb_AreawhereCity='"+ddlCity.SelectedItem.Text+"'";SqlDataAdaptermydaArea=newSqlDataAdapter(strArea,sqlcon);DataSetmydsArea=newDataSet();mydaArea.Fill(mydsArea);ddlArea.DataSource=mydsArea;ddlArea.DataValueField="Area";ddlArea.DataBind();sqlcon.Close();}//codego.net/tags/11/1///点选按钮显示下级菜单protectedvoidddlProvince_SelectedIndexChanged(objectsender,EventArgse){sqlcon=newSqlConnection(strCon);stringsqlstr="select*fromtb_CitywhereProvince='"+ddlProvince.SelectedItem.Text+"'";SqlDataAdaptermyda=newSqlDataAdapter(sqlstr,sqlcon);DataSetmyds=newDataSet();sqlcon.Open();myda.Fill(myds);ddlCity.DataSource=myds;ddlCity.DataValueField="City";ddlCity.DataBind();sqlcon.Close();}protectedvoidddlCity_SelectedIndexChanged(objectsender,EventArgse){sqlcon=newSqlConnection(strCon);stringsqlstr2="select*fromtb_AreawhereCity='"+ddlCity.SelectedItem.Text+"'";SqlDataAdaptermysda=newSqlDataAdapter(sqlstr2,sqlcon);DataSetmyds2=newDataSet();sqlcon.Open();mysda.Fill(myds2);ddlArea.DataSource=myds2;ddlArea.DataValueField="Area";ddlArea.DataBind();sqlcon.Close();}