C# DropDownList所选索引在asp中回发后发生更改

C# DropDownList所选索引在asp中回发后发生更改,c#,asp.net,.net,C#,Asp.net,.net,我的网页上有3个下拉列表,第一个是州,第二个是地区,第三个是城市 <asp:DropDownList ID="stateddl" OnSelectedIndexChanged="stateddl_SelectedIndexChanged" AutoPostBack="true" runat="server" CssClass="form-control"></asp:DropDownList> Select District:

我的网页上有3个下拉列表,第一个是州,第二个是地区,第三个是城市

<asp:DropDownList ID="stateddl" OnSelectedIndexChanged="stateddl_SelectedIndexChanged" AutoPostBack="true" runat="server" CssClass="form-control"></asp:DropDownList>
                Select District:
               <asp:DropDownList ID="districtddl" OnSelectedIndexChanged="districtddl_SelectedIndexChanged" AutoPostBack="true" runat="server" CssClass="form-control" ViewStateMode="Enabled"></asp:DropDownList>
                Select Area:
               <asp:DropDownList ID="cityddl" runat="server" CssClass="form-control"></asp:DropDownList>
我已经在页面加载时从db填充状态,如果用户选择任何状态,则在
selectedindexchanged
事件中加载所选状态的所有区域。 但问题是,如果用户选择任何状态
selectedindexchanged
事件激发并发回。回发DropDownList后,每次选择ddl的第一个值。
我怎样才能解决这个问题。对不起,我的英语不好。

如果不查看页面加载事件,很可能每次回发时都会运行下拉列表的初始填充。 您需要做的是使用page.IsPostBack检查页面加载事件中的初始加载,它告诉您页面是否是第一次访问服务器

private void Page_Load()
{
    if (!Page.IsPostBack)
    {
        YourPopulationOfDdFunction();
    }
}

请显示后面的代码。#Bob Swager问题已用my.cs文件的代码更新此问题类似。在页面加载时,您是否尝试过使用if(!Page.IsPostBack){code here}执行代码
private void Page_Load()
{
    if (!Page.IsPostBack)
    {
        YourPopulationOfDdFunction();
    }
}
    Narender Godara! i think the issue is when u call first drop down on page load u have to use condition
    if(!ispostback)
    {
    //code of first dropdown %states
    } 
    then u have to write the next code in the selectedindexchanged of first dropdown and so on....
by the way your english is better than many developers of aisa, so bro keep it up, stay blessed,
#Good Luck