DataTable dt = BargainPriceBrowseBO.GetProductClassDropDownList(this.GetUser().CurrentProjectID.ToString()); this.ddl_ProductClass.DataSource = dt;
this.ddl_ProductClass.DataTextField = "PCLASS_NAME";
this.ddl_ProductClass.DataValueField = "ID";
this.ddl_ProductClass.DataBind();

解决方案 »

  1.   

    这个是ListBox,和DropDownList是一样的,不过我的这个是在DataGrid里面的((ListBox)grid.Items[ItemIndex].FindControl(ListBoxName)).DataSource=myOA.GetDepartmentsName().DefaultView;
    ((ListBox)grid.Items[ItemIndex].FindControl(ListBoxName)).DataTextField="departname";
    ((ListBox)grid.Items[ItemIndex].FindControl(ListBoxName)).DataValueField="departid";
    ((ListBox)grid.Items[ItemIndex].FindControl(ListBoxName)).DataBind();
      

  2.   

    1130protected void InitDDL()
    1131{
    1132string strSelect="select TemplateName,ID from Template";
    1133OleDbCommand cmm=new OleDbCommand(strSelect,Conn);
    1134Conn.Open();
    1135OleDbDataReader rd=cmm.ExecuteReader();
    1136lstTemplateName.DataSource=rd;
    1137lstTemplateName.DataTextField="TemplateName";
    1138lstTemplateName.DataValueField="ID";
    1139lstTemplateName.DataBind();
    1140lstTemplateName.Items.Insert(0,"选择模板名");
    1141rd.Close();
    1142Conn.Close();
    1143}
      

  3.   

    youdropdownlist.DataSource = 'your dataview';
    youdropdownlist.DataBind();
      

  4.   

    我是这样绑定的,每绑定一个都要这样重复,不知道有没有什么好点方法?
    conn.Open(); SqlCommand cmd1=new SqlCommand("select  DISTINCT  xibie_id  from daima",conn); ddlxibie.DataSource=cmd1.ExecuteReader();
    ddlxibie.DataTextField="xibie_id";
    ddlxibie.DataValueField="xibie_id";
    ddlxibie.DataBind(); conn.Close();

    conn.Open(); SqlCommand cmd2=new SqlCommand("select  DISTINCT  nianji_id from daima",conn); ddlnianji.DataSource=cmd2.ExecuteReader();
    ddlnianji.DataTextField="nianji_id";
    ddlnianji.DataBind(); conn.Close();
      

  5.   

    在page_load里面 DropDownList1.DataSource=User.GetUnit();
    DropDownList1.DataValueField="UnitID";
    DropDownList1.DataTextField="UnitName";
    DropDownList1.DataBind();