开发者

dropdwnlist autopostback not working

开发者 https://www.devze.com 2023-03-23 17:53 出处:网络
dropdwnlist autopostback not working my code as follows: <asp:DropDownList ID=\"ddlState\" runat=\"server\" Width=\"200px\" AutoPostBack=\"true\" onselectedindexchanged=\"ddlState_SelectedIndexCh

dropdwnlist autopostback not working my code as follows:

<asp:DropDownList ID="ddlState" runat="server" Width="200px" AutoPostBack="true" onselectedindexchanged="ddlState_SelectedIndexChanged" >
   <%--  <asp:ListItem Selected="True">--Select--</asp:ListItem>--%>
</asp:DropDownList>

Codebehind is:

protected void ddlState_SelectedIndexChanged(object sender, EventArgs e)
{
    ddlDistrict.Enabled = true;
    ddlTaluka.Enabled = true;
    DataTable dtObj = new DataTable();
    using (var client = ServiceClient<IPallaviAddressManager>.Create("PallaviAddressManager"))
    {
        dtObj = client.In开发者_StackOverflow社区stance.GetAllStates();
    }
    var result = (from dt in dtObj.AsEnumerable()
                      where dt.Field<Int64>("StateID") == Convert.ToInt64(ddlState.SelectedValue)
                      select dt);
    dtObj = result.CopyToDataTable();
    ddlDistrict.DataSource = dtObj;
    ddlState.DataTextField = "Description";
    ddlState.DataValueField = "DistrictID";
}

Can you help?


Try adding ddlDistrict.DataBind(); at the end of the code, as Shadow Wizard suggested


It sounds like the event hasn't been hooked up properly.

Try selecting the DropDownList control in the designer, going to the properties tab and double clicking in the space to the right of the SelectedIndexChanged event, if it creates a new stub in the code-behind then the original event wasn't hooked properly.


Set it to runat="server" and autopostback="true"

0

精彩评论

暂无评论...
验证码 换一张
取 消