三级联动练习

问题描述

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();}

时间: 2024-09-14 13:49:13

三级联动练习的相关文章

一个用webservice behavior实现的三级联动下拉列表框

web|下拉|下拉列表 我做了一个三级联动的下拉列表框,后台用webservice,前台用webservice behavior与后台通讯.请高手们多提改进意见. server端:(service1.asmx.cs)using System;using System.Text;using System.Configuration;using System.Collections;using System.ComponentModel;using System.Data;using System.

php+js+ajax+mysql实现省市三级联动

效果如下图: 思路:先获取所选省的市或者是所选时的县,将获取的数据转换为jason格式的字符串返回到ajax客户端,在客户端使用eval将jason格式的字符串转化为对象,将对象的每个元素值创建成文本节点,并创建option节点,将文本节点追加到option节点,在将option的节点追加给select节点. ajax-area-select.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &

简单实用jquery版三级联动select示例

本文主要为大家介绍下通过jquery实现三级联动select这里用到的json文件,只是事例,根据情况添加或编写,感兴趣的朋友可以参考下哈,希望对大家有所帮助   html和js部分 复制代码 代码如下: <!DOCTYPE html> <html> <head> <meta charset=gbk /> <title>selectList</title> <style type="text/css">

jquery读取xml文件实现省市县三级联动的方法

  本文实例讲述了jquery读取xml文件实现省市县三级联动的方法.分享给大家供大家参考.具体如下: 页面代码如下: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66

javascript实现简单的省市区三级联动

  本文给大家反映的是javascript实现的简单的省市区三级联动特效,不需要访问后台服务器端,不使用Ajax,无刷新,纯JS实现的省市区三级联动.当省市区数据变动是只需调正js即可. 当我们注册一个网站,会看到省市区三级联动,下面简单介绍一下 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 4

JS制作简单的三级联动

 本文给大家分享的是使用javascript实现的一个简单的三级联动菜单,非常简单实用,有需要的小伙伴过来参考下吧.     用javascript制作的一个简单三级联动,非常简单实用   代码如下: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> </head> <body> 省: <selec

Django Web实现动态三级联动

1.平台环境     操作系统:Windows 7 64位     开发环境:Eclipse PyDev 2.文件夹结构     直接看下面的图片:     目前很多文件还用不上,在创建Django的项目时或app时,很多文件都是自动生成的,下面会说一说可以用得上的文件. 3.主要功能文件与代码 (1)MapPro/settings.py     目前主要是用来设置statics和templates,告诉Django这两个目录的存在路径,添加的代码如下: 1 2 3 4 5 6 7 TEMPLA

简单实现ajax三级联动效果

本文实例为大家分享了ajax三级联动效果展示的具体代码,供大家参考,具体内容如下 主页面代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="../wenjian/jquery-2.2.3.min.js"></sc

Android使用android-wheel实现省市县三级联动_Android

今天没事跟群里面侃大山,有个哥们说道Android Wheel这个控件,以为是Andriod内置的控件,google一把,发现是个github上的一个控件. 下载地址:https://code.google.com/p/android-wheel/    发现很适合做省市县三级联动就做了一个. 先看下效果图: 1.首先导入github上的wheel项目 2.新建个项目,然后选择记得右键->Properties->Android中将wheel添加为lib: 上面两个步骤是导入所有开源项目的过程了

基于jQuery+JSON的省市二三级联动效果_jquery

省市区联动下拉效果在WEB中应用非常广泛,尤其在一些会员信息系统.电商网站最为常见.开发者一般使用Ajax实现无刷新下拉联动.本文将讲述,利用jQuery插件,通过读取JSON数据,实现无刷新动态下拉省市二(三)级联动效果. HTML 首先在head中载入jquery库和cityselect插件. <script type="text/javascript" src="js/jquery.js"></script> <script ty