用vs2008做城市定位,DropDownList1省名,DropDownList2市名。
DropDownList2没有东西显示usingSystem;usingSystem.Collections;usingSystem.Configuration;usin...
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个回答
Storm代理
2023-07-25 广告
2023-07-25 广告
StormProxies是一家国内优质海外HTTP代理商,拥有一个庞大的IP资源池,覆盖200多个地区,IP数量大且匿名度高。其优点还包括超高并发、稳定高效、技术服务等特点,同时提供HTTP、HTTPS以及SOCKS5协议支持。此外,Sto...
点击进入详情页
本回答由Storm代理提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询