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();

  • 相关阅读:
    工厂模式
    dubbo
    WebSocket WebService
    消息中间
    原型模式
    ApiPost Apifox
    Future 的使用与源码解析
    JUC 线程池的使用与源码解析
    ReentrantLock 源码解析
    CountDownLatch 的使用与源码解析
  • 原文地址:https://www.cnblogs.com/newwind521/p/692080.html
Copyright © 2011-2022 走看看