Asp.net 下拉列表设置为System.Data.DataRow,我的代码有什么问题?
上述代码将下拉项设置为System.Data.DataRow 如何获取实际值?尝试如下操作:Asp.net 下拉列表设置为System.Data.DataRow,我的代码有什么问题?,asp.net,vb.net,drop-down-menu,datatable,dataset,Asp.net,Vb.net,Drop Down Menu,Datatable,Dataset,上述代码将下拉项设置为System.Data.DataRow 如何获取实际值?尝试如下操作: System.Data.DataTable dt = new System.Data.DataTable(); CDbAccess db = new CDbAccess(); IDbConnection conn = db.GetConnectionInterface(); conn.Open(); string str = "select eName from
System.Data.DataTable dt = new System.Data.DataTable();
CDbAccess db = new CDbAccess();
IDbConnection conn = db.GetConnectionInterface();
conn.Open();
string str = "select eName from bt_modules";
IDbCommand cmd = db.GetCommandInterface(str);
IDbDataAdapter da = db.GetDataAdapterInterface(cmd);
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds);
dt = ds.Tables[0];
DropDownList2.DataSource = dt;
DropDownList2.DataBind();
conn.Close();
如果您想使用值字段,也可以这样使用
DropDownList2.DataSource = dt;
DropDownList1.DataTextField = "eName " '// Column Name
DropDownList2.DataBind();
DropDownList2.DataSource=ds
DropDownList2.DataTextField=eName
DropDownList2.DataBind
康涅狄格州关闭
你也可以参考这段代码Google将对此有所帮助-非常基本你想在哪里获得dropdownlist2中的数据?@SATSON我想用Vb绑定dropdownlist2。net@SATSON它将下拉项设置为System.Data.DataRow,而不是名称
DropDownList2.DataSource = dt;
DropDownList1.DataTextField = "eName " '// Column Name
DropDownList1.DataValueField = "eid" '// Column Name
DropDownList2.DataBind();