本文介绍了下拉列表代码有问题请帮忙吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 /*C# code*/using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;namespace Dropdown{ public partial class WebForm1 : System.Web.UI.Page { String[] country = new String[] {"--Select Country--","India" }; String[] State = new String[] { "--Select State--", "Ap","Telangana" }; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DropDownList1.DataSource = country; DropDownList1.DataBind(); } } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { int i = DropDownList1.SelectedIndex; if (i == 1) { foreach (String stat in State) { DropDownList2.Items.Add(stat); } } } protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e) { } }}/*ASP.net Code*/ 我的尝试: 两个控件 - Dropdownlist1(国家) - Dropdownlist1(国家) i能够在page_load上加载dropwdownlist1和国家名称() 但是在dropdownlist1_selectedindex改变了......我无法加载第二个下拉列表 i已经尝试了 protected void DropDownList1_SelectedIndexChanged(object sender,EventArgs e) { int i = DropDownList1.SelectedIndex; if(i == 1) { DropDownList2.DataSource =州; } Dro pDownList2.DataBind(); } What I have tried:Two Controls - Dropdownlist1 (Country) - Dropdownlist1 (States)i am able to load dropwdownlist1 with countries names on page_load()but upon dropdownlist1_selectedindex changed ... i cant load second dropdownlisti have tried protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { int i = DropDownList1.SelectedIndex; if (i == 1) { DropDownList2.DataSource=State; }DropDownList2.DataBind(); }推荐答案 List<string> State = new List<string>(new String[] { "--Select State--", "Ap","Telangana"});protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { int i = DropDownList1.SelectedIndex; if (i == 1) { DropDownList2.DataSource = State; DropDownList2.DataBind(); } }</string></string> 谢谢Thanks 这篇关于下拉列表代码有问题请帮忙吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-12 02:17