省市级连 采用DropDownList 本帖最后由 x1aoli 于 2011-11-03 22:34:49 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 第一个省市下拉框加事件 DropDownList1_SelectedIndexChanged触发事件后得到第一个下拉的值,在查询到城市的数据 绑定第二个下拉框 <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"></asp:DropDownList><asp:DropDownList ID="DropDownList2" runat="server"></asp:DropDownList>public void Page_Load(object sender,EventArgs e){ if(!IsPostBack) { this.DropDownList1.DataSource = getDataSet("Province"); this.DropDownList1.DataTextField= "ProvinceName"; this.DropDownList1.DataValueField= "ID"; this.DropDownList1.DataBind(); this.DropDownList1.Items.Insert(0,"--请选择--"); } }public void DropDownList1_SelectedIndexChanged(object sender,EventArgs e){ if(this.DropDownList1.SelectedIndex!=0) { this.DropDownList2.DataSource = getDataSet("City",int.Parse(this.DropDownList1.SelectedItem.Value)); this.DropDownList2.DataTextField= "CityName"; this.DropDownList2.DataValueField= "ID"; this.DropDownList2.DataBind(); }} //获取数据集 ,根据你实际的数据库连接字符串进行相应修改public DataSet getDataSet(string tableName) { DataSet ds = new DataSet(); using (SqlConnection con = new SqlConnection("Data Source=localhost;uid=sa;pwd=sa;Database=CSDN")) { con.Open(); string strSQL = "select * from "+tableName; using (SqlDataAdapter sda = new SqlDataAdapter(strSQL, con)) { sda.Fill(ds); } } return ds; } public DataSet getDataSet(string tableName,int args) { DataSet ds = new DataSet(); using (SqlConnection con = new SqlConnection("Data Source=localhost;uid=sa;pwd=sa;Database=CSDN")) { con.Open(); string strSQL = "select * from "+tableName+" where PID="+args; using (SqlDataAdapter sda = new SqlDataAdapter(strSQL, con)) { sda.Fill(ds); } } return ds; } like this:http://www.cnblogs.com/insus/archive/2011/07/04/2097059.html 怎样得到字符串截取后的剩余字符 在线等啊,关于前台正则表达式转成后台代码 选择复选框改变汇总的值 奇怪!奇怪!真奇怪!!! 时间无法显示 一个JS找控件的问题 请教:关于动态绑定SqlDataSource到GridView与DetailsView 求救,急!!!! 关于Microsoft.Office.Interop.Excel的问题 求助:使用IE7,水晶报表无法使用PDF打印和导出 gridview 动态生成的的checkbox 如何在一行显示多个
触发事件后得到第一个下拉的值,在查询到城市的数据
绑定第二个下拉框
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"></asp:DropDownList><asp:DropDownList ID="DropDownList2" runat="server"></asp:DropDownList>public void Page_Load(object sender,EventArgs e)
{
if(!IsPostBack)
{
this.DropDownList1.DataSource = getDataSet("Province");
this.DropDownList1.DataTextField= "ProvinceName";
this.DropDownList1.DataValueField= "ID";
this.DropDownList1.DataBind();
this.DropDownList1.Items.Insert(0,"--请选择--");
}
}public void DropDownList1_SelectedIndexChanged(object sender,EventArgs e)
{
if(this.DropDownList1.SelectedIndex!=0)
{
this.DropDownList2.DataSource = getDataSet("City",int.Parse(this.DropDownList1.SelectedItem.Value));
this.DropDownList2.DataTextField= "CityName";
this.DropDownList2.DataValueField= "ID";
this.DropDownList2.DataBind();
}
} //获取数据集 ,根据你实际的数据库连接字符串进行相应修改
public DataSet getDataSet(string tableName)
{
DataSet ds = new DataSet();
using (SqlConnection con = new SqlConnection("Data Source=localhost;uid=sa;pwd=sa;Database=CSDN"))
{
con.Open();
string strSQL = "select * from "+tableName;
using (SqlDataAdapter sda = new SqlDataAdapter(strSQL, con))
{
sda.Fill(ds);
}
}
return ds;
} public DataSet getDataSet(string tableName,int args)
{
DataSet ds = new DataSet();
using (SqlConnection con = new SqlConnection("Data Source=localhost;uid=sa;pwd=sa;Database=CSDN"))
{
con.Open();
string strSQL = "select * from "+tableName+" where PID="+args;
using (SqlDataAdapter sda = new SqlDataAdapter(strSQL, con))
{
sda.Fill(ds);
}
}
return ds;
}
http://www.cnblogs.com/insus/archive/2011/07/04/2097059.html