dropdownlist.datasuorce=tablename;
dropdownlist.DataTextField = "你要显示的字段名";
dropdownlist.DataValueField = "你要存值的字段名";
dropdownlist.DataBind();
dropdownlist.DataTextField = "你要显示的字段名";
dropdownlist.DataValueField = "你要存值的字段名";
dropdownlist.DataBind();
{
SqlConnection conn = new SqlConnection(WLIB.SqlCnStr);
string str_coun="select country_name,country_code from dmb_coun order by country_name";
SqlDataAdapter Myunitadp = new SqlDataAdapter(str_coun,conn);
DataSet ds_coun=new DataSet();
DDL_country.DataSource=ds_coun;
DDL_country.DataTextField="country_name";
DDL_country.DataValueField="country_code";
conn.Open();
Myunitadp.Fill(ds_coun);
DDL_country.DataBind();
DDL_country.SelectedIndex=0;
conn.Close();
}
dropdownlist.datasuorce=DataSet;
dropDownList.DataMember=DataTableName;
dropdownlist.DataTextField = "你要显示的字段名";
dropdownlist.DataValueField = "你要存值的字段名"; 然后在Page_load()
{
if(!IsPostBack)
{
dropdownlist.DataBind();
}}
DataSet ds = new DataSet();
DropDownList.DataSource = ds;
其中CDB112中我已经定义好了,连接
string sql_zaxx;
sql_zaxx="select * from dic_matter";
CDB112 newmat= new CDB112();
System.Data.OleDb.OleDbDataReader eader=null;
newmat.MakeDataSet(ref myreader, sql_zaxx);
dropdl_zaxx.DataSource=myreader;
dropdl_zaxx.DataMember=dic_matter;
dropdl_zaxx.DataTextField = "matter_name";
dropdl_zaxx.DataValueField = "matter_id";
dropdl_zaxx.DataBind(); if (myreader == null)
return;
this.dropdl_zaxx.DataSource=myreader;
this.dropdl_zaxx.DataBind();
{
SqlCommand Comm=new SqlCommand("select CustMngrID,CustMngrName from T_CUST_MNGR where ChargeID=@cid",Conn);
Comm.Parameters.Add("@Cid",SqlDbType.VarChar);
Comm.Parameters["@Cid"].Value=MangID;
if(Conn.State.ToString()!="Open")
Conn.Open();
try
{
SqlDataReader Reader=Comm.ExecuteReader();
DropDownList1.DataValueField="CustMngrID";
DropDownList1.DataTextField="CustMngrName";
DropDownList1.DataSource=Reader;
DropDownList1.DataBind();
Reader.Close();
}
谁能给个例子
Dim Dynaset As Object
Dim OraDatabase As ObjectSQL = "SELECT field1, field2 ..."
Dynaset = OraDatabase.DbCreateDynaset(SQL, 0)
Dynaset.DbMoveFirst()
Do Until Dynaset.EOF
DropDownList1.Items.Add(Dynaset.Fields("field1").Value & " " & Dynaset.Fields("field2").Value)
Dynaset.MoveNext()
Loop
然后在Page_load()
if(!IsPostBack)
{
dropdownlist1.DataBind();
}