0

I try to update the ddlBuilding but it don't show anything . and ddlBuilding show nothing too .( work without UpdatePanel it show is ok.)

<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
    <ContentTemplate>
    <div class="form-group  col-md-12">
        <label for="name">PCCC</label>
        <asp:DropDownList ID="ddlDistrict" runat="server" CssClass="form-control select2 select2-hidden-accessible" OnSelectedIndexChanged="ddlDistrict_SelectedIndexChanged" AutoPostBack="True">
        </asp:DropDownList>
    </div>
    <div class="form-group  col-md-12">
        <label for="name">Building</label>
        <asp:DropDownList ID="ddlBuilding" runat="server" class="form-control select2 select2-hidden-accessible">
        </asp:DropDownList>
    </ContentTemplate>
</asp:UpdatePanel>

Code behind .

protected void Page_Load(object sender, EventArgs e)
{

    if (!Page.IsPostBack)
    {
            FillDistrict();
    }

}
void FillDistrict()
{
    DataTable district = Instant.GetAllDistrict();
    ddlDistrict.DataSource = district;
    ddlDistrict.DataValueField = "id";
    ddlDistrict.DataTextField = "district_name";
    ddlDistrict.DataBind();
}

protected void ddlDistrict_SelectedIndexChanged(object sender, EventArgs e)
{
    DataTable buildingz = Instant.GetBuildingByDistrictID(int.Parse(ddlDistrict.SelectedValue));
    ddlBuilding.DataSource = buildingz;
    ddlBuilding.DataValueField = "id";
    ddlBuilding.DataTextField = "building_name";
    ddlBuilding.DataBind();
}

sr my english is bad

Hossein Golshani
  • 1,847
  • 5
  • 16
  • 27
  • check out this link https://stackoverflow.com/a/1257029/9650643 – Usha phulwani Sep 21 '18 at 03:59
  • It's seems everything are fine in your code. Please look into console, is there any exception showing? Also, debug your code with try catch block and let me know what your are getting. – Jitendra G2 Sep 21 '18 at 05:21

2 Answers2

0

You Need to Add Triggers to your Update Panel in the markup after

<ContentTemplate>
 .....
</ContentTemplate>

<Triggers>
            <asp:AsyncPostBackTrigger ControlID="ddlDistrict" 
                EventName="SelectedIndexChanged" />
        </Triggers>
Gagan Deep
  • 1,508
  • 9
  • 13
  • Have you tried to put a break point on the ddlDistrict_SelectedIndexChanged event. see if you are getting any exception there. – Gagan Deep Sep 21 '18 at 04:54
0

You need to update your update panel.

So for that write below code in your dropdown selected index change method

protected void ddlDistrict_SelectedIndexChanged(object sender, EventArgs e)
{
    DataTable buildingz = Instant.GetBuildingByDistrictID(int.Parse(ddlDistrict.SelectedValue));
    ddlBuilding.DataSource = buildingz;
    ddlBuilding.DataValueField = "id";
    ddlBuilding.DataTextField = "building_name";
    ddlBuilding.DataBind();
    UpdatePanel1.Update()
}

Because you have set UpdateMode="Conditional", So you have to update it from code.

Kevin Shah
  • 1,589
  • 1
  • 13
  • 20