1

3 つのドロップダウン リスト ddl1、ddl2、および ddl3 があります。

ddl1 の項目を選択すると、ddl2 と同様に ddl3 のそれぞれの項目が入力されます。

例:- ddl1 で「インド」を選択すると、ddl2 はすべての州を表示し、ddl3 はインドのすべての都市を表示する必要があります。データベース接続なしでこれを行いたいです(htmlからの静的なだけです)。助けてください!!!。ありがとう。

4

5 に答える 5

0
  private SqlConnection conn = your connection string;
    public void Bind_ddlcountry()
    {
        conn.Open();
        SqlCommand cmd = new SqlCommand("select countryid,country from tblcountry", conn);
        SqlDataReader dr = cmd.ExecuteReader();
        ddlcountry.DataSource = dr;
        ddlcountry.Items.Clear();
        ddlcountry.Items.Add("--Please Select country--");
        ddlcountry.DataTextField = "Country";
        ddlcountry.DataValueField = "CountryId";
        ddlcountry.DataBind();
        conn.Close();
    }

// 同様に州と都市をバインドします..

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)

        {    Bind_ddlcountry(); }

    }
    protected void ddlcountry_selectedindexchanged(object sender, EventArgs e)
    {
        Bind_ddlstate();
        ddlstate.Focus();
    }
    protected void ddlstate_selectedindexchanged(object sender, EventArgs e)
    {
        Bind_ddlcity();
        ddlcity.Focus();
    }
于 2013-05-16T10:36:03.927 に答える
0

データベースにリンクしていないため、IfElse ステートメントを使用する方が適切です。の線に沿った何か

if (dropdownlist1.selectedValue == "India")
{
    dropdownlist2.items.clear();
    dropdownlist2.items.add("CityName");
    dropdownlist2.items.add("CityName");
    dropdownlist2.items.add("CityName");
    dropdownlist2.items.add("CityName");
    dropdownlist2.items.add("CityName");
    dropdownlist2.items.add("CityName");
    dropdownlist2.items.add("CityName");
}

これを国ごとにコピー アンド ペーストします。非常に反復的ですが効果的です。

于 2013-06-20T10:11:31.127 に答える
0

I had a same situation some days ago , it should be accomplished something like populating all the data in lists on page load and then filtering the lists via jquery and ajax and dynamically binding them to dropdowns. I tried but didn't succeeded. so I used Ajaxtoolkit's cascading dropdowns.

于 2013-05-17T11:43:04.760 に答える