using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls;namespace UserWeb { public partial class WebForm1 : System.Web.UI.Page {
public string[] gradeList = new string[] { "一年级", "二年级", "三年级" }; public string[] classList1 = new string[] { "一班", "二班", "三班", "四班" }; public string[] classList2 = new string[] { "一班", "二班", "三班" }; public string[] classList3 = new string[] { "一班", "二班" }; public string[] studentName = new string[] { "1", "2" }; public string[] studentName1 = new string[] { "2", "3" }; public string[] studentName2 = new string[] { "4", "5" }; protected void Page_Load(object sender, EventArgs e) { ASPxComboBoxGrade.DataSource = gradeList; ASPxComboBoxGrade.DataBind(); }
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;namespace UserWeb
{
public partial class WebForm1 : System.Web.UI.Page
{
public string[] gradeList = new string[] { "一年级", "二年级", "三年级" };
public string[] classList1 = new string[] { "一班", "二班", "三班", "四班" };
public string[] classList2 = new string[] { "一班", "二班", "三班" };
public string[] classList3 = new string[] { "一班", "二班" };
public string[] studentName = new string[] { "1", "2" };
public string[] studentName1 = new string[] { "2", "3" };
public string[] studentName2 = new string[] { "4", "5" };
protected void Page_Load(object sender, EventArgs e)
{
ASPxComboBoxGrade.DataSource = gradeList;
ASPxComboBoxGrade.DataBind();
}
protected void ASPxComboBoxGrade_SelectedIndexChanged(object sender, EventArgs e)
{
ASPxComboBoxGrade.Items.Clear();
ASPxComboBoxGrade.Items.Add(gradeList[0]);
ASPxComboBoxGrade.Items.Add(gradeList[1]);
ASPxComboBoxGrade.Items.Add(gradeList[2]);
string grade = 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();
}
else if( 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();
}
else if (grade == gradeList[2])
{
ASPxComboBoxClass.Items.Clear();
ASPxComboBoxClass.Items.Add(classList3[0]);
ASPxComboBoxClass.Items.Add(classList3[1]);
ASPxComboBoxClass.DataSource = classList3;
ASPxComboBoxClass.DataBind();
} } protected void ASPxComboBoxClass_SelectedIndexChanged(object sender, EventArgs e)
{
string class1 = ASPxComboBoxClass.SelectedItem.ToString();
if (class1 == gradeList[0])
{
ASPxComboBoxStudentName.Items.Clear();
ASPxComboBoxStudentName.Items.Add(studentName[0]);
ASPxComboBoxStudentName.Items.Add(studentName[1]);
}
else if (class1 == gradeList[1])
{
ASPxComboBoxStudentName.Items.Clear();
ASPxComboBoxStudentName.Items.Add(studentName1[0]);
ASPxComboBoxStudentName.Items.Add(studentName[1]); }
else if (class1 == gradeList[2])
{
ASPxComboBoxStudentName.Items.Clear();
ASPxComboBoxStudentName.Items.Add(studentName[0]);
ASPxComboBoxStudentName.Items.Add(studentName[1]); }
} protected void ASPxComboBoxStudentName_SelectedIndexChanged(object sender, EventArgs e)
{ }
}
}刚才发的不对,这个事,求帮帮忙改一改呀
ASPxComboBoxGrade.Items.Clear();
ASPxComboBoxGrade.Items.Add(gradeList[0]);
ASPxComboBoxGrade.Items.Add(gradeList[1]);
ASPxComboBoxGrade.Items.Add(gradeList[2]);
这里为什么要清空他又加回来?没什么意义啊。 string grade = ASPxComboBoxGrade.SelectedItem.Value.ToString(); 试试 以下的SelectedItem也这样改看看。
//下拉框控件设置
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:DropDownList ID="ddlProvince" runat="server" AutoPostBack="True"
onselectedindexchanged="ddlProvince_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="ddlCity" runat="server" AutoPostBack="true"
onselectedindexchanged="ddlCity_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="ddlArea" runat="server">
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
//加载数据库信息显示
SqlConnection sqlcon;
string strCon = ConfigurationManager.AppSettings["conn"];
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
sqlcon = new SqlConnection(strCon);
string sqlstr = "select Province from tb_Province";
sqlcon.Open();
SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon);
DataSet myds = new DataSet();
myda.Fill(myds);
ddlProvince.DataSource= myds;
ddlProvince.DataValueField = "Province";
ddlProvince.DataBind(); string strCity = "select * from tb_City where Province='" + ddlProvince.SelectedItem.Text + "'";
SqlDataAdapter mydaCity = new SqlDataAdapter(strCity, sqlcon);
DataSet mydsCity = new DataSet();
mydaCity.Fill(mydsCity);
ddlCity.DataSource = mydsCity;
ddlCity.DataValueField = "City";
ddlCity.DataBind(); string strArea = "select * from tb_Area where City='" + ddlCity.SelectedItem.Text + "'";
SqlDataAdapter mydaArea = new SqlDataAdapter(strArea, sqlcon);
DataSet mydsArea = new DataSet();
mydaArea.Fill(mydsArea);
ddlArea.DataSource = mydsArea;
ddlArea.DataValueField = "Area";
ddlArea.DataBind();
sqlcon.Close();
}//codego.net/tags/11/1/
//点选按钮显示下级菜单
protected void ddlProvince_SelectedIndexChanged(object sender, EventArgs e)
{
sqlcon = new SqlConnection(strCon);
string sqlstr = "select * from tb_City where Province='" + ddlProvince.SelectedItem.Text + "'";
SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon);
DataSet myds = new DataSet();
sqlcon.Open();
myda.Fill(myds);
ddlCity.DataSource = myds;
ddlCity.DataValueField = "City";
ddlCity.DataBind();
sqlcon.Close();
}
protected void ddlCity_SelectedIndexChanged(object sender, EventArgs e)
{
sqlcon = new SqlConnection(strCon);
string sqlstr2 = "select * from tb_Area where City='" + ddlCity.SelectedItem.Text + "'";
SqlDataAdapter mysda = new SqlDataAdapter(sqlstr2, sqlcon);
DataSet myds2 = new DataSet();
sqlcon.Open();
mysda.Fill(myds2);
ddlArea.DataSource = myds2;
ddlArea.DataValueField = "Area";
ddlArea.DataBind();
sqlcon.Close();
}