向ListBox中添加一行,确保不是重复的字符串,有什么属性可以设置码?还是要自己写代码控制?

解决方案 »

  1.   

    if(ListBox.Items.Contains("你的ITEM值")==false)
    {
        ListBox.Items.Add("你的ITEM值");
    }
      

  2.   

    ListItem li=new ListItem("你的值","你的文本");
    if(ListBox1.Items.Contains(li))
    {
        ListBox1.Items.Add("你的ITEM值");
    }
    或者
    if(ListBox1.Items.FindByValue("你的值")!=null)
    {
        ListBox1.Items.Add("你的ITEM值");
    }
      

  3.   

    sorry,应该是
    ListItem li=new ListItem("你的值","你的文本");
    if(!(ListBox1.Items.Contains(li)))
    {
        ListBox1.Items.Add("你的ITEM值");
    }
      

  4.   

    if(ListBox.Items.Contains("你的ITEM值")==false)
    {
        ListBox.Items.Add("你的ITEM值");
    }
    怎么得到listbox选中的index?
    ListBox.Items.SelectedIndex
      

  5.   

    怎么得到listbox选中的index?
    string str = this.DropDownList1.SelectedIndex.ToString();