用c#做一个城市选择,DropDownList1为省,DropDownList2为市。
比如DropDownList1选了浙江,DropDownList2有浙江省的市的选择。可是DropDownList2空白。求帮助!!!usingSystem;usingS...
比如DropDownList1选了浙江,DropDownList2有浙江省的市的选择。可是DropDownList2空白。
求帮助!!!
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Data;
public partial class Default5 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList2.Items.Clear();
String abc = DropDownList1.Text;
String serstr = @"server=dell-pc;uid=sa;pwd=111111;database=yzq ";
SqlConnection mycon = new SqlConnection(serstr);
mycon.Open();
String select = @"select 市名from shi where 省id=' " + abc + " '";
SqlCommand mycommand = new SqlCommand(select, mycon);
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = mycommand;
DataSet ds = new DataSet();
da.Fill(ds);
DataTable mytable = ds.Tables[0];
//设定list2的数据源
DropDownList2.DataSource = mytable;
DropDownList2.DataTextField = "市名";
DropDownList2.DataValueField = "市名";
DropDownList2.DataBind();
mycon.Close();
}
} 展开
求帮助!!!
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Data;
public partial class Default5 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList2.Items.Clear();
String abc = DropDownList1.Text;
String serstr = @"server=dell-pc;uid=sa;pwd=111111;database=yzq ";
SqlConnection mycon = new SqlConnection(serstr);
mycon.Open();
String select = @"select 市名from shi where 省id=' " + abc + " '";
SqlCommand mycommand = new SqlCommand(select, mycon);
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = mycommand;
DataSet ds = new DataSet();
da.Fill(ds);
DataTable mytable = ds.Tables[0];
//设定list2的数据源
DropDownList2.DataSource = mytable;
DropDownList2.DataTextField = "市名";
DropDownList2.DataValueField = "市名";
DropDownList2.DataBind();
mycon.Close();
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询