0

1 つの Web ページに 2 つのドロップダウン リストがあります。2 番目のものは、ロードする最初のものに依存しています。たとえば、最初のリストが「Melbourne」の場合、2 番目のリストにはメルボルンのすべての郊外がリストされます。

コードは完全に機能していますが、最初にページをロードしたときに、2 番目の dropdownlist2 が読み込まれません。2 番目のドロップダウンリストに入力するには、「Melbourne」をもう一度選択する必要があります。

これがページ読み込みのコードです

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        if (Session["Username"] == null)
        {
            Response.Redirect("LoginPage.aspx");
        }

        if (getAccess(Session["Username"].ToString()) == false)
        {
            Response.Redirect("Unauthorized.aspx");
        }

        DataSet ds = GetAllCategory();
        if (ds.Tables.Count > 0)
        {
            DropDownList1.DataTextField = "identifier";
            DropDownList1.DataValueField = "OS_ID"; //Change field to one you want.
            DropDownList1.DataSource = ds.Tables[0];
            DropDownList1.DataBind();
        }
    }
}

そして、ここに選択されたインデックス変更コードがあります

 protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
    DataSet ds = softwareType(Convert.ToInt32(DropDownList1.SelectedValue));
    if (ds.Tables.Count > 0)
    {
        DropDownList2.DataTextField = "identifier";
        DropDownList2.DataValueField = "ST_ID"; //Change field to one you want.
        DropDownList2.DataSource = ds.Tables[0];
        DropDownList2.DataBind();
    }
}

この単純な問題を修正する方法がわかりませんか?

4

7 に答える 7