zoukankan      html  css  js  c++  java
  • comboBox dropdownlist droplist 添加 value

    1. public class ListItem   
    2. {   
    3.     private string _key = string.Empty;   
    4.     private string _value = string.Empty;   
    5.     public ListItem(string pKey, string pValue)   
    6.     {   
    7.         _key = pKey;   
    8.         _value = pValue;   
    9.     }   
    10.     public override string ToString()   
    11.     {   
    12.         return this._value;   
    13.     }   
    14.     public string Key   
    15.     {   
    16.         get  
    17.         {   
    18.             return this._key;   
    19.         }   
    20.         set  
    21.         {   
    22.             this._key = value;   
    23.         }   
    24.     }   
    25.     public string Value   
    26.     {   
    27.         get  
    28.         {   
    29.             return this._value;   
    30.         }   
    31.         set  
    32.         {   
    33.             this._value = value;   
    34.         }   
    35.     }   
    36. }   
    37.   
    38.   
    39. ///////////////////////////////////////////////////////////////   
    40. comboBox1.Items.Add(new ListItem("请选择""0"));   
    41. DataView dv = Comm.DB.ExecuteDataSet("select txtName,ID from dept where ParentID=24").Tables[0].DefaultView;   
    42. foreach (DataRowView drv in dv)   
    43. {   
    44.     comboBox1.Items.Add(new ListItem(drv["txtName"].ToString() , drv["ID"].ToString()));   
    45. }   
    46. comboBox1.DisplayMember = "Key";   
    47. comboBox1.ValueMember = "Value";   
    48. comboBox1.SelectedIndex = 0;   
    49.   
    50. ///////////////////////////////////////////////////////////////////   
    51.  MessageBox.Show(((ListItem)comboBox1.SelectedItem).Value); 
  • 相关阅读:
    Java 泛型 泛型的约束与局限性
    Java 泛型 泛型方法
    Java 泛型 泛型数组
    Java 泛型 协变性、逆变性
    Java 泛型 协变式覆盖和泛型重载
    Java 泛型 泛型代码和虚拟机
    Insertion Sort List
    Remove Duplicates from Sorted List II
    String to Integer (atoi)
    SpringMvc源码入门
  • 原文地址:https://www.cnblogs.com/liufei88866/p/1762647.html
Copyright © 2011-2022 走看看