私はC#asp.net Webフォームを初めて使用していますが、すべてのトレッドを検索しますが、回答はありませんでした。データベースから値をドロップダウンリスト
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString; //read from web.config.
SqlConnection con = new SqlConnection(constr);
DataTable dt = new DataTable();
con.Open();
SqlDataReader myReader = null;
SqlCommand cmd = new SqlCommand("select * from gender", con);
myReader = cmd.ExecuteReader();
while (myReader.Read())
{
ddlmarrital.DataSource = myReader; //assigning datasource to the dropdownlist
ddlmarrital.DataTextField = "field"; // text field name of table dispalyed in dropdown
ddlmarrital.DataValueField = "ID"; // to retrive specific textfield name
ddlmarrital.DataBind(); //binding dropdownlist
}
con.Close();
table1(性別)1.male 2.female。
Mastertable1(名称 "ABC")。(性別「男性)。(アドレス "ABC")
私が保存された値(Mastertable1.gender)を表示したい、と私は値を変更したい場合私が選択するためにドロップダウンリストを使用することができます。ツールボックスからWebフォーム上のSqlDataSourceオブジェクトをドロップ
ループを削除します。しかし、問題は何ですか? – Steve
"Mastertable1" .genderの値をドロップダウンリストに表示することができません。 – sakura
しかし、MasterTableの値が必要な場合は、なぜGenderテーブルをクエリしますか? – Steve