📜  在c#代码示例中将数据源分配给下拉列表

📅  最后修改于: 2022-03-11 14:48:54.481000             🧑  作者: Mango

代码示例1
cmd.CommandText = " Select * From GetUsersID";
        cmd.Connection = conn;
        conn.Open();
        DataTable dt  = new DataTable();

        dt.Load(cmd.ExecuteReader());
        conn.Close();

        DropDownList1.DataSource = dt;
        DropDownList1.DataTextField = "Name";
        DropDownList1.DataValueField = "ID";
        DropDownList1.DataBind();