DropDownList控件调用onselectedindexchanged事件无效
前台代码:<td width="75%">
<asp:DropDownList ID="address_sheng" runat="server" CssClass="areacss"
AutoPostBack="true"
onselectedindexchanged="address_sheng_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="address_city" runat="server" CssClass="areacss">
</asp:DropDownList>
</td>
后台代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetCoures();
//事件注册
// this.address_sheng.SelectedIndexChanged += new System.EventHandle(this.address_sheng_SelectedIndexChanged);
}
}
public void GetCoures()
{
this.address_sheng.DataSource = new B_City().getarr(1);
this.address_sheng.DataValueField = "C_Sid";
this.address_sheng.DataTextField = "C_name";
this.address_sheng.DataBind();
ListItem li = new ListItem("--请选择--", "0");
this.address_sheng.Items.Insert(0, li);
GetCity();
}
public void GetCity()
{
ListItem li = new ListItem("--请选择--", "0");
this.address_city.Items.Insert(0, li);
}
void address_sheng_SelectedIndexChanged(object sender, EventArgs e)
{
int sid =Convert.ToInt32(this.address_sheng.SelectedValue);
this.address_city.DataSource = new B_City().getAll_city(sid);
this.address_city.DataValueField = "C_id";
this.address_city.DataTextField = "C_name";
this.address_city.DataBind();
ListItem li = new ListItem("--请选择--", "0");
this.address_city.Items.Insert(0, li);
}
根据断点调试可知:当address_sheng的value值发生改变时向服务器发布了请求 只不过是Page_Load页面刷新 并木有调用address_sheng_SelectedIndexChanged方法