如何将select筛选出来的结果逐个添加到dropdownlist的item中去?谢谢!

解决方案 »

  1.   

    foeach(DataRow row in rows)
    {
     ListItem item = new ListItem();
     item.Text = row["text"].ToString();
     item.value = row["value"].ToString();
     this.DDL1.Items.Add(item);
    }
      

  2.   

    new啊 ListItem listitem = new ListItem("text", "value");
    this.DropDownList.Items.Add(listitem);
      

  3.   

    Dim item as New ListItem
    其他一样啊.
      

  4.   

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["aaa"].ConnectionString))
                {
                    SqlDataAdapter sda = new SqlDataAdapter("select CategoryID,CategoryName  from Categories", connection);
                    DataSet ds = new DataSet();
                    sda.Fill(ds);
                    DropDownList1.DataSource = ds;
                    DropDownList1.DataTextField = "CategoryName";
                    DropDownList1.DataValueField = "CategoryID";
                    DropDownList1.DataBind();
                }
            }
        }
      

  5.   

    foeach(DataRow row in rows)
    {
    this.DDL1.Items.Add(new ListItem(row["text"].ToString(),row["value"].ToString()));
    }