SortedList小用


使用SortedList类建立排序的DropDownList 
SortedList 类类似于 Hashtable 和 ArrayList 间的混合。与 Hashtable 一样,SortedList 也基于 IDictionary 接口

;因此,SortedList 的每一元素都是键和值对。SortedList 提供只返回键列表或只返回值列表的方法。与 ArrayList 

一样,SortedList 是元素序列。它被索引,并且根据特定的比较器被排序。SortedList 在所有 Collections 类中是唯

一的,在其中每一元素都可通过三种方式访问:使用键、值或索引。

如果您想要一个保存键
/值对的集合并且还需要索引列表的灵活性,请使用 SortedList。

-------------------------------------------------------------------------------------------------
示例:


 SortedList Sl
=new SortedList();
 Sl.Add(
"项一","1");
 Sl.Add(
"项二","2");
 Sl.Add(
"项三","3");
 Sl.Add(
"项四","4");

//绑定DropDownList
DropDownList1.DataSource 
= Sl;
DropDownList1.DataValueField 
= "Value" ;
DropDownList1.DataTextField 
= "Key" ;
DropDownList1.DataBind() ;

  
Private _Detail_Qty_List As SortedList
  
Public Property Detail_Qty_List() As SortedList
        
Get
            
Return _Detail_Qty_List
        
End Get
        
Set(ByVal Value As SortedList)
            _Detail_Qty_List 
= Value
        
End Set
    
End Property

    
            
If Me._Detail_Qty_List.Count > 0 Then
                
For Each itmQty As DictionaryEntry In Me._Detail_Qty_List
                    
If Not (itmQty.Value = 0Then
                        strSQL 
= "UPDATE Return_Detail SET Detail_Qty=" & itmQty.Value & " WHERE SN=" & 

itmQty.Key 
& ""
                        run.ExecuteNonQuery(conn.CONN_STRING, CommandType.Text, strSQL)                   
                    
End If
                
Next
            
End If
posted @ 2005-12-30 20:07  blueKnight  Views(356)  Comments(0Edit  收藏  举报