1. 程式人生 > >DropDownList按照Gridview獲取數據獲取到的是定義格式

DropDownList按照Gridview獲取數據獲取到的是定義格式

lec pan SQ tab oracle sel efi 取數 服務器

首先需要把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獲取數據獲取到的是定義格式