0
[...]
public DataSet ReturnPromoMagazinesDs()
{
MySql.Data.MySqlClient.MySqlConnection mysqlConnection = new MySql.Data.MySqlClient.MySqlConnection(this.connectionString);
MySql.Data.MySqlClient.MySqlCommand mysqlCommand = new MySql.Data.MySqlClient.MySqlCommand("SELECT id, magazine_name FROM `magazines`", mysqlConnection);
MySql.Data.MySqlClient.MySqlDataAdapter mysqlAdaptor = new MySql.Data.MySqlClient.MySqlDataAdapter(mysqlCommand);
DataSet ds = new DataSet();
mysqlAdaptor.Fill(ds, "magazines");
return ds;
}
[...]
protected void Page_Load(object sender, EventArgs e)
{
DataSet ds = new DataSet();
ds = coreObject.ReturnPromoMagazinesDs();
DropDownList1.DataSource = ds;
DropDownList1.DataTextField = ds.Tables["magazines"].Columns["magazine_name"].ColumnName;
DropDownList1.DataValueField = ds.Tables["magazines"].Columns["id"].ColumnName;
DropDownList1.DataBind();
}
[...]
<asp:dropdownlist id="DropDownList1" runat="server"></asp:dropdownlist>
上面的代碼工作正常,直到我取了DropDownList1.SelectedValue這始終是1(從表中的拳頭值)。表中的值不是責任,如果我手動添加項目到DropDownList,一切工作正常。什麼會導致這種情況?ASP.NET DropDownList的問題
兩種方式產生相同的結果。即使我在droptdownlist.datasource = ds之前或之後使用dropdown.datetextfiel =「myfield」和dropdown.datatextvaluefield =「id」 – EsiX 2009-09-07 11:16:11