DropDownList1.DataSource=ArrayList1;
DropDownList1.DataBind();

解决方案 »

  1.   

    <html>
    <head>
       <script language="C#" runat="server">
          void Page_Load(Object sender, EventArgs e)
          {
             if(!IsPostBack)
             {
                ArrayList myList = new ArrayList();
                myList.Add ("Item 1");
                myList.Add ("Item 2");
                myList.Add ("Item 3");
                myList.Add ("Item 4");
                myList.Add ("Item 5");
                DropDownList1.DataSource = myList;
                DropDownList1.DataBind();
             }
          }
           
          void Button_Click(Object sender, EventArgs e) 
          {
             Label1.Text = "You selected " + DropDownList1.SelectedItem.Text + ".";  
          }
       </script>
    </head>
     
    <body>
       <form runat="server">
          <h3>DropDownList Data Bind Example</h3>
          Select an item from the list and click the submit button.
          <p>
          <asp:DropDownList id="DropDownList1" 
               runat="server"/>
          <br><br>
          <asp:Button id="Button1" 
               Text="Submit" 
               OnClick="Button_Click" 
               runat="server"/>
          <br><br>
          <asp:Label id="Label1" 
               runat="server"/>
       </form>
    </body>
    </html>
      

  2.   

    这段代码,我已经调试了,OK。 System.Collections.ArrayList myAL = new System.Collections.ArrayList(); 
    myAL.Add("Hello");
    myAL.Add("World");
    myAL.Add("!");

    DropDownList1.DataSource=myAL;
    DropDownList1.DataBind();
      

  3.   

    1、先定义接口
    public interface IDepartment
    {
    IList GetSuperDept();
    }2、在业务层里调用借口
    public class Department
    {
    //
    // 在接口查找方法
    //
    public IList GetSuperDept()
    {
                IDepartment dept=KenWang.DALFactory.Department.Create();
    return dept.GetSuperDept();

    }
    3、在工厂层里建立实例
    public static KenWang.IDAL.IDepartment Create()
    {
    //
    // path,classname
    //
    string path=ConfigurationSettings.AppSettings["WebDAL"];
    string classname=path+".Department"; //建立Instance
    return (KenWang.IDAL.IDepartment)Assembly.Load(path).CreateInstance(classname); }
    4、数据层里的方法
    public IList GetSuperDept()
    { IList GetSuperDept=new ArrayList();
    SqlDataReader rdr=SqlBase.GetDataReaderByExecute(SqlBase.SqlConnectString,USP);
    while (rdr.Read())
    {
    DepartmentInfo department=new DepartmentInfo(rdr.GetInt32(0),rdr.GetString(1));
    GetSuperDept.Add(department);

    }
    return GetSuperDept;
    }本来目的想得到sqldatareader这样Dropdownlist可以直接绑定
    可是Ilist不支持datareader返回 只好用arraylist