数据库中的某某表中的某列有如下内容:红色|绿色|兰色(用分隔符|分开)现想把  红色|绿色|兰色  在dropdownlist中显示出来,并附上VALUE值
┏━━━━┓
┗━━━━┛
  红色
  绿色
  兰色
希望能详细回答!谢谢!

解决方案 »

  1.   

    value的值可以定义一个数组吧?
      

  2.   

    先考虑把把  红色|绿色|兰色  在dropdownlist中显示出来
      

  3.   

    提取数据字段的值到一个string 之后split("|")分割string[]数组 或添加到arraylist
    将dropdownlist的datasource设置为arraylist对象实例即可
      

  4.   

    string color = "红色|绿色|兰色";
                string[] str = color.Split('|');
                for (int i = 0; i < str.Length; i++)
                {
                    DropDownList2.Items.Add(str[i]);
                }
      

  5.   

    ListItem li;
    string color = "红色|绿色|兰色";
    string[] str = color.Split('|');
    Hashtable ht = new Hastable();
    ht.Add(str[0],"red");
    ........
    ........
    for (int i = 0; i < str.Length; i++)
    {
       li = new ListItem(str[i].ToString(),ht[str[0]])
       DropDownList.Items.Add(li);
    }