Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 下拉列表设置为System.Data.DataRow,我的代码有什么问题?_Asp.net_Vb.net_Drop Down Menu_Datatable_Dataset - Fatal编程技术网

Asp.net 下拉列表设置为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.DataRow

如何获取实际值?

尝试如下操作:

    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();