<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %><%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI" TagPrefix="asp" %><!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">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>       
    </div>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged1"
                    Style="position: relative">
                </asp:DropDownList><br />
                <asp:DropDownList ID="DropDownList2" runat="server"
                    Style="position: relative">
                </asp:DropDownList>
            </ContentTemplate>
        </asp:UpdatePanel>
    </form>
</body>
</html>
在加入了UpdatePane之后 下面的方法就不执行了protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(sqlConString);
        con.Open();
        SqlCommand cmd = new SqlCommand("select * from city where proID='" + this.DropDownList1.SelectedValue.Trim() + "'", con);
        SqlDataReader sdr = cmd.ExecuteReader();
        this.DropDownList2.DataSource = sdr;
        this.DropDownList2.DataTextField = "cityName";
        this.DropDownList2.DataValueField = "cityID";
        this.DropDownList2.DataBind();
        sdr.Close();
        con.Close();
    }高手指点下...

解决方案 »

  1.   


    没错,DropDownList1 的 AutoPostBack="true";
    还有就是楼主是不是漏了给DropDownList1 付值了??没有值不会触发SelectedIndexChanged事件的.<asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 
                    onselectedindexchanged="DropDownList1_SelectedIndexChanged">
                    <asp:ListItem>1</asp:ListItem>
                    <asp:ListItem>2</asp:ListItem>
                    <asp:ListItem>3</asp:ListItem>
                </asp:DropDownList>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="DropDownList1" 
                    EventName="SelectedIndexChanged" />
            </Triggers>
        </asp:UpdatePanel>跟踪一下,就能看到执行了.
     protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {    }
      

  2.   

    补充:AutoPostBack="true"; 后,只是刷新updatepanel 局部区域.