0

これらの構文を使用して 2 つのドロップダウン リストに入力しました。最初のドロップダウン リストを選択した後、2 番目のドロップダウン リストに入力する必要がありますが、2 番目のドロップダウン リストは空です。mysql テーブルには、ドロップダウン リストに入力する 2 つのテーブルがあり、最初のテーブルには (gov_name) と(gove_id) で、2 番目のものには (area_name) と (gov_id) が含まれます。

{
    DataSet ds_1;
    ListItem item_1;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            fill_gov();
        }
    }

    private void fill_gov()
    {
        //Session["conection"] = "Data Source=MEDICONSULT;Initial Catalog=test1;Integrated Security=True";
        Session["conection"] = "Data Source=MEDICONSULT;Initial Catalog=test1;Integrated Security=True";

        SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString);
        connection.Open();
        SqlCommand command = new SqlCommand();
        connection = new SqlConnection((string)Session["conection"]);
        connection.Open();
        SqlDataAdapter da_1 = new SqlDataAdapter(command);
        da_1 = new SqlDataAdapter();
        command = new SqlCommand();
        command.Connection = connection;
        command.CommandText = "select gov_name from gov";
        da_1.SelectCommand = command;
        ds_1 = new DataSet();
        da_1.Fill(ds_1, "gov");
        Session["Hospital"] = DropDownList1.SelectedIndex;
        DropDownList1.Items.Clear();
        item_1 = new ListItem();
        item_1.Value = "0";
        item_1.Text = "select governement";
        DropDownList1.Items.Add(item_1);
        for (int i = 0; i <= ds_1.Tables[0].Rows.Count - 1; i++)
        {
            item_1 = new ListItem();
            item_1.Value = (ds_1.Tables[0].Rows[i]["gov_name"].ToString());
            item_1.Text = ds_1.Tables[0].Rows[i]["gov_name"].ToString();
            DropDownList1.Items.Add(item_1);
        }

    }

    private void fill_area()
    {
       // Session["conection"] = "Data Source=MEDICONSULT;Initial Catalog=test1;Integrated Security=True";
        Session["conection"] = "Data Source=MEDICONSULT;Initial Catalog=test1;Integrated Security=True";

        SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString);
        connection.Open();
        SqlCommand command = new SqlCommand();
        connection = new SqlConnection((string)Session["conection"]);
        connection.Open();
        SqlDataAdapter da_1 = new SqlDataAdapter(command);
        da_1 = new SqlDataAdapter();
        command = new SqlCommand();
        command.Connection = connection;
        command.CommandText = "select area_name from area where area_name !='' and cast (gov_id as varchar) ='" + DropDownList1.SelectedValue + "'";
        da_1.SelectCommand = command;
        ds_1 = new DataSet();
        da_1.Fill(ds_1, "area");
        Session["Hospital"] = DropDownList2.SelectedIndex;
        DropDownList2.Items.Clear();
        item_1 = new ListItem();
        item_1.Value = "0";
        item_1.Text = "select area";
        DropDownList2.Items.Add(item_1);
        for (int i = 0; i <= ds_1.Tables[0].Rows.Count - 1; i++)
        {
            item_1 = new ListItem();
            item_1.Value = (ds_1.Tables[0].Rows[i]["area_name"].ToString());
            item_1.Text = ds_1.Tables[0].Rows[i]["area_name"].ToString();
            DropDownList2.Items.Add(item_1);
        }

    }
4

1 に答える 1