UpdatePanel不管用,还是刷新整个页面
HTML:
<%@ Page Language="C#" MasterPageFile="~/Main.master" AutoEventWireup="true" EnableEventValidation="false" CodeFile="Issuance.aspx.cs" Inherits="Issuance" Title="Untitled Page" %>
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div id="crumb">
<div id="path">
<h1>您的位置:</h1>
<a href="#">首页>></a><a href="#">用户登陆</a>
</div>
</div>
<div id="middlePan">
<div id="publish1">
<img src="images/publish_img.gif" width="101" height="64" class="title_img" />
<h1>发布商品</h1>
<form name="form1" id="form1" method="post" action="">
<table>
<tr>
<td>
<asp:ScriptManager id="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<table style="width: 122px">
<tbody>
<tr>
<td>
<asp:DropDownList ID="ddlPro" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlPro_SelectedIndexChanged"></asp:DropDownList>
</td>
<td>
<asp:DropDownList ID="ddlCity" runat="server" AutoPostBack="True" Enabled="False"></asp:DropDownList>
</td>
<td>
<asp:DropDownList ID="ddlRegion" runat="server" Enabled="False"></asp:DropDownList>
</td>
</tr>
</tbody>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
</table>
</form>
</div>
</div>
</asp:Content>
cs:
sing 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.Data.SqlClient;
public partial class Issuance : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//if (Session["user"] = "")
// Response.Redirect("Default.aspx");
BindToCityandTown();
}
}
protected void BindToCityandTown()
{
//這裏綁定城市
string Citystr = "SELECT ProvinceName FROM Province";
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["SQLCon"]);
SqlDataAdapter da = new SqlDataAdapter(Citystr, con);
DataSet ds = new DataSet();
da.Fill(ds);
this.ddlPro.DataSource = ds;
this.ddlPro.DataTextField = "ProvinceName";
this.ddlPro.DataValueField = "ProvinceName";
this.ddlPro.DataBind();
this.ddlPro.Items.Insert(0, "选择省份");
}
protected void ddlPro_SelectedIndexChanged(object sender, EventArgs e)
{
ddlCity.Items.Clear();
ddlCity.Enabled = true;
string Citystr = "SELECT c.CityName FROM City c LEFT OUTER JOIN Province p ON p.ProvinceName = '" + ddlPro.SelectedValue.ToString() + "' RIGHT OUTER JOIN Province AS p1 ON p1.ProvinceID = c.ProvinceID GROUP BY c.CityName";
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["SQLCon"]);
SqlDataAdapter da = new SqlDataAdapter(Citystr, con);
DataSet ds = new DataSet();
da.Fill(ds);
this.ddlCity.DataSource = ds;
this.ddlCity.DataTextField = "CityName";
this.ddlCity.DataValueField = "CityName";
this.ddlCity.DataBind();
this.ddlCity.Items.Insert(0, "选择商圈");
}
}
老大们帮我看看咋回事啊??