dropdownlist怎么赋值的....比如说...有一个dropdownlist....当页面一加载的时候...dropdownlist的就从数据库里得到...是手写代码的...

解决方案 »

  1.   


    string sqldl = "select BID,BName from News";
    if (!IsPostBack)
            {
                DataSet dsdl = t.getDataSet(sqldl, "News");
                DropDownList1.DataSource = dsdl.Tables["News"];
                DropDownList1.DataValueField = "BID";
                DropDownList1.DataTextField = "BName";
                DropDownList1.SelectedIndex = 0;
                DataBind();
           }
      

  2.   

    DataSet dsItems = new  DataSet ();访问数据库填充 dsItems DropItem.DataTextField = "OrderItemName";
    DropItem.DataValueField = "OrderItemID";
    DropItem.DataSource = dsItems ;
    DropItem.DataBind();
      

  3.   

    写到Page_Load事件中
    if(!IsPostBack)
    {
     this.DropDownList1.DataSource=dt;//从数据库取得
     this.DropDownList1.DataTextField="Name";// 要显示的字段
     this.DropDownList1.DataValueField = "ID";//字段Value
     this.DropDownList1.DataBind();
    }