62,041
社区成员
发帖
与我相关
我的任务
分享
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script type="text/javascript" src="jquery-1.2.6.pack.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function(){
$("#bTrade").change(function(){
$("#sTrade").load("getprovinces.aspx?id="+$("#bTrade").val()) ;
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<select name="bTrade" id="bTrade">
<option value="-1">——所属省份——</option>
<%=provicename%> <!--输出省份-->
</select>
<select name='sTrade' id="sTrade">
<option value='-2'>——城市——</option>
</select>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString);
public string provicename = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
StringBuilder st = new StringBuilder();
SqlCommand comm=new SqlCommand("select * from provinces",conn);
conn.Open();
SqlDataReader dr = comm.ExecuteReader(CommandBehavior.CloseConnection);
while(dr.Read())
{
st.Append("<option value="+dr["provincetype"].ToString()+">----"+dr["province"].ToString()+"----</option>");
}
dr.Close();
conn.Close();
provicename = st.ToString();
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="getprovinces.aspx.cs" Inherits="getstrade" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Data.SqlClient;
public partial class getstrade : System.Web.UI.Page
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString);
public string cityname = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
StringBuilder st = new StringBuilder();
SqlCommand comm = new SqlCommand("select * from citiesTb where provincetype="+Request.QueryString["id"].ToString(), conn);
conn.Open();
SqlDataReader dr = comm.ExecuteReader(CommandBehavior.CloseConnection);
while (dr.Read())
{
st.Append("<option value=" + dr["provincetype"].ToString() + ">----" + dr["cityname"].ToString() + "----</option>");
}
dr.Close();
conn.Close();
cityname =st.ToString();
Response.Write(cityname);
Response.End();
}
}