很简单的例子,代码如下:
<%@Page Language="C#"%>
<script runat="server">
public class DropDownList: System.Web.UI.Page
{
    protected System.Web.UI.WebControls.DropDownList dropdownlist1;
protected System.Web.UI.WebControls.Button button1;
protected System.Web.UI.WebControls.Label Label1;
void Page_load(Object Sender,EventArgs E)
{
    if(!Page.IsPostBack)
{
ArrayList myArray = new ArrayList();
myArray.Add(new ListItem("a","a"));
myArray.Add(new ListItem("b","b"));
dropdownlist1.DataSource = myArray;
dropdownlist1.DataBind();
}
}
}
public void Button_Click(object sender,EventArgs e)
{
label1.Text="你选择了"+ dropdownlist1.SelectedItem.Text +".";
}
</script>
<form id="form1" runat="server">
<asp:DropDownList id="dropdownlist1" runat="server"></asp:DropDownList>
<br/><br/>
<asp:Button id="button1" Text="Submit" OnClick="Button_Click" runat="server"/>
<br/><br/>
<asp:Label id="label1" Text="" runat="server"/>
</form>

解决方案 »

  1.   

    给你个例子:
    public void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    if(!IsPostBack)
    {
    string MyConnString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath(".")+ConfigurationSettings.AppSettings["DataBase"];
    OleDbConnection MyConn=new OleDbConnection(MyConnString);
    MyConn.Open(); string sqlstr="select * from PrintType";
    OleDbCommand MyComm=new OleDbCommand(sqlstr,MyConn);

    //DateSet ds=new DataSet();
    DataSet ds=new DataSet();
    OleDbDataAdapter MyAdapter=new OleDbDataAdapter(sqlstr,MyConn);
    MyAdapter.Fill(ds,"Score");
    this.Brand.DataSource=ds.Tables["Score"];
    this.Brand.DataTextField="small_class_data";
    this.Brand.DataValueField="small_class_data";
    this.Brand.DataBind();
    this.Brand.Items.Insert(0,new ListItem("请选择","0"));
    MyConn.Close();
    }
               
    }
      

  2.   

    DataView dv;
    dv赋值后
    .......
    if(dv.count>0)
    {
       for(int i=0;i<dv.Count;i++)
       {
         dropdownlist1.Items .Add(new ListItem(dv[i]["字段"].tostring()));
       }
    }
      

  3.   

    this.DropDownList1.DataSource = dataSet.Tables[0];
    this.DropDownList1.DataTextField = dataSet.Tables[0].Columns[1].ColumnName;
    this.DropDownList1.DataValueField = dataSet.Tables[0].Columns[0].ColumnName;
    this.DropDownList1.DataBind();
      

  4.   

    //指定数据源
    dropdownlist1.DataSource = myArray;
    //指定绑定的字段
    this.DropDownList1.DataTextField = "字段0";//myArray中的字段
    this.DropDownList1.DataValueField = "字段1";//myArray中的字段
    dropdownlist1.DataBind();