【发布时间】:2016-07-06 08:29:38
【问题描述】:
我是 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),如果我想更改该值,我可以使用下拉列表进行选择。
【问题讨论】:
-
删除循环。不需要,但是有什么问题?
-
我无法将“Mastertable1”.gender 上的值显示在下拉列表中。
-
但是如果您需要 MasterTable 中的值,那么为什么要查询 Gender 表呢?
-
您能说得更具体些吗?目前的结果是什么?如果可能,请发布屏幕截图。
-
嗨史蒂夫,可能是我使用了错误的方法。我打算在该字段上显示 mastertable 值。如果我想更改,我可以更改为 table1 中的值。