好像要加上
DropDownList1.DataTextField="字段名";DropDownList1.DataValueField="字段名";

解决方案 »

  1.   


    楼上正解
    this.DropDownList1.DataSource=this.allusername;DropDownList1.DataTextField="字段名";DropDownList1.DataValueField="字段名";
    this.DropDownList1.DataBind();
      

  2.   

    那我帮定的是textfield还是valuefield呢
      

  3.   

    我的字段名应该怎么设置,他因该和值是一样的,DropDownList1.DataTextField=this.allusername.......什么麽...
      

  4.   

    protected void InitList(DropDownList list,string strsql,string TextField,string ValueField)
    {
    Conn.Open();
    Cmd =new OleDbCommand(strsql,Conn);
    OleDbDataReader Rd = Cmd.ExecuteReader();
    list.DataSource=Rd;
    list.DataTextField=TextField;//你的DDl内的item显示的内容
    list.DataValueField=ValueField;//你的ddl的item生成的html<option value=...中value的值
    list.DataBind();
    list.SelectedIndex = 0;
    Rd.Close();
    Conn.Close();
    }}
      

  5.   

    this.allusername=this.username_f.getmenber(aa);
     //allusername 是datareader,返回一个表的记录
      this.DropDownList1.DataSource=this.allusername;
     DropDownList1.DataTextField="MemberName";  DropDownList1.DataValueField="MemberName";

     this.DropDownList1.DataBind();
    绑定完了以后,下拉出来所有的用户名,但是无论我选哪个用户名,他的值都是下拉选项中第一个用户名的值,晕,而且selectindex 永远都是0,还有,DropDownList1_SelectedIndexChanged事件在我选择的时候也不触发,这是怎么回事呀,大哥
      

  6.   

    SqlConnection cn=new System.Data.SqlClient.SqlConnection (conStr);
    cn.Open();
    string cmStr="select * from researchtab where tablename='"+tablename+"'" ;
    SqlCommand cm=new SqlCommand (cmStr,cn);
    SqlDataReader dr=cm.ExecuteReader();
    while (dr.Read())
    {
    DropDownList1.Items.Add(new ListItem(dr["chinesename"].ToString(),dr["FieldName"].ToString()));
    LX.Items.Add(new ListItem(dr["ReferTab"].ToString(),dr["Kind"].ToString()));
                  
    }
      

  7.   

    你必须加上
    if(!IsPostBack)
    {
    //绑定程序
    ......}
      

  8.   


    if(!IsPostBack)
    {
    BindDp();}
    public void BindDp()
    {
    //绑定程序}