protected void Page_Load(object sender, EventArgs e)
    {
        
     string[] stringArray = new  string[6];
     stringArray[0] = "a";
     stringArray[1] = "b";
     stringArray[2] = "c";
     stringArray[3] = "d";
     stringArray[4] = "e";
     stringArray[5] = "f";
     for (int i = 0; i < stringArray.Length; i++) {
         this.DropDownList1.Items.Add(new ListItem(stringArray[i]));
        
     }    }这样DropDownList1.SelectedItem.ToString()也是a,b,c,d,e,f了也就是说如果让value为0,1,2,3,4,5

解决方案 »

  1.   

    this.DropDownList1.Items.Add(new ListItem(stringArray[i], i));
      

  2.   

    this.DropDownList1.Items.Add(new ListItem(stringArray[i], i)); 
    正解
      

  3.   

     void listData()
        {
            List<controlData> cd = new List<controlData>();
            cd.Add(new controlData("one", "0.1"));
            cd.Add(new controlData("two", "0.2"));
            cd.Add(new controlData("three", "0.3"));
            cd.Add(new controlData("four", "0.4"));
            cd.Add(new controlData("five", "0.5"));
            cd.Add(new controlData("six", "0.6"));
            cd.Add(new controlData("seven", "0.7"));
            cd.Add(new controlData("eight", "0.8"));
            cd.Add(new controlData("nine", "0.9"));
            cd.Add(new controlData("ten", "1.0"));        tools.controlData.BindList(cd, "strid", "strname", ListBox1);
            tools.controlData.BindList(cd, "strid", "strname", ListBox2);
            tools.controlData.BindList(cd, "strid", "strname", ListBox3);
            tools.controlData.BindList(cd, "strid", "strname", ListBox4);
            tools.controlData.BindList(cd, "strid", "strname", ListBox5);
            tools.controlData.BindList(cd, "strid", "strname", ListBox6);
            tools.controlData.BindList(cd, "strid", "strname", ListBox7);
            tools.controlData.BindList(cd, "strid", "strname", ListBox8);
            tools.controlData.BindList(cd, "strid", "strname", ListBox9);
            
        }
    楼主改一下
      

  4.   

    我在DropDownList控件里加入 AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
    为什么每选一次就都会增加列表的项目.
    比如初使是6项选择一次就大于6项了
      

  5.   

    dropdownlist.datatextfield="绑定的字段名";
      

  6.   

    /// <summary>
            /// 继承基类ListControl的数据控件,如:DropDownList,ListBox,CheckBoxList,RadioButtonList,BulletedList.
            /// 参数 string text 可以为空.
            /// </summary>
            public static void BindList(object dataSource, string text, string value, ListControl lst)
            {
                lst.DataSource = dataSource;
                lst.DataTextField = text;
                lst.DataValueField = value;
                lst.DataBind();
            }
      

  7.   

    this.DropDownList1.Items.Add(new ListItem(stringArray[i], i)); 
      

  8.   

    this.DropDownList1.Items.Add(new ListItem(stringArray[i], i)); 
      

  9.   

    this.DropDownList1.Items.Add(new ListItem(stringArray[i], i)); 
    正解
      

  10.   


    this.DropDownList1.Items.Add(new ListItem(stringArray[i], i)); 
      

  11.   

    this.DropDownList1.Items.Add(new ListItem(stringArray[i],i));p.s楼主连“如何”和“如果”都分不清?
      

  12.   

    dropdownlist.datatextfield="绑定的字段名";
    dropdownlist.dataVAluefield="编号";