[原创]如何将数据和dropdownlist绑定
如何将数据库中的某个字段和dropdownlist绑定?
private void Page_Load(object sender, System.EventArgs e)
{
OleDbConnection conn = new OleDbConnection;
conn.connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("shop.mdb");
conn.open();
OleDbDataAdapter myda = new OleDbDataAdapter("select * form Category",conn);
DataSet myds=new DataSet ();
myda.Fill (myds,"Category");
GoodsClass.DataSource =myds.Tables ["Category"];
GoodsClass.DataTextField="Category"; // Category和ID为字段名
GoodsClass.DataValueField ="ID";
GoodsClass.DataBind ();
conn.close();
}
这样写行吗?