zoukankan      html  css  js  c++  java
  • 如何用HashTable数据源绑定DropDownList控件?

    如何用HashTable数据源绑定DropDownList控件?

    直接绑定
    但是要指定 dropdownlist的text和value 分别为 hashtable的 key和value

    Hashtable ht = new Hashtable();
       for(int i=0; i<10; i++)
       {
        ht.Add(i+1,"Item"+1);
       }
       this.DropDownList1.DataSource = ht;
       this.DropDownList1.DataTextField = "key";
       this.DropDownList1.DataValueField = "value";
       
       this.DropDownList1.DataBind();
       // Put user code to initialize the page here
      }

    我现在用一个datadownlist控件绑定一个hashtable,为什么在down控件中绑定hashtable的时候项目不是顺序的,而是无顺序的呢?
    怎么解决这个问题呀?

    把HashTable换成SortedList试试,SortedList是HashTable和Array的混合,既有HashTable的功能,也有ArrayList的排序功能


    用arraylist,怎样才能同时确定key又确定value啊??????

    ArrayList al=new ArrayList();
    al.Add(new ListItem("--请选择--","0"));
    al.Add(new ListItem("综合新闻","1"));
    ......
    L_flags.DataSource=al;
    this.DropDownList1.DataSource=al;
        this.DropDownList1.DataTextField="Text";
        this.DropDownList1.DataValueField="Value";
        this.DropDownList1.DataBind();

  • 相关阅读:
    有向无环图单源最短路径问题
    linux下程序编译出错解决方法
    Ceres入门笔记
    Java 中的数据结构类 Vector 和 ArrayList
    102. Binary Tree Level Order Traversal
    104. Maximum Depth of Binary Tree
    101. Symmetric Tree
    100. Same Tree
    490. The Maze
    骑士游历问题
  • 原文地址:https://www.cnblogs.com/newwind521/p/692080.html
Copyright © 2011-2022 走看看