DropDownList按照Gridview获取数据获取到的是定义格式

Posted 杨松岩

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了DropDownList按照Gridview获取数据获取到的是定义格式相关的知识,希望对你有一定的参考价值。

首先需要把DropDownList改成允许服务器返回。

然后绑定的时候需要以下两项。

DropDownList1.DataTextField = "name";
DropDownList1.DataValueField = "name";

完整例子

using System.Data;
using System.Data.OracleClient;

string str = "Data Source=127.0.0.1/xkp;User ID=jsb;PassWord=jsb";
string sql = "select name from userlist";
OracleConnection conn = new OracleConnection(str);
OracleDataAdapter dr = new OracleDataAdapter(sql, conn);
DataSet ds = new DataSet();//创建数据集;
dr.Fill(ds); //填充数据集
DropDownList1.DataSource = ds;
DropDownList1.DataTextField = "name";
DropDownList1.DataValueField = "name";
DropDownList1.DataBind();
if (conn.State == ConnectionState.Open) //判断数据库连接状态,是否连接
{
conn.Close();
}

以上是关于DropDownList按照Gridview获取数据获取到的是定义格式的主要内容,如果未能解决你的问题,请参考以下文章