2016-05-26 3 views
0

ListBoxから重複したアイテムを削除するためにListItemにフィールドを追加する前に、- 重複したアイテムフォームを削除する方法Listbox

I want here the code where removes duplicates... 

これはSPListの要素を追加するコードです。

foreach (ListItem listItem in _lboxRight.Items) 
{ 
    sb.Append(listItem + "; "); 
} 

sb.Remove(sb.Length - 2, 1); 

item["Project"] = sb; 
+0

は私に答えを与える... – Gohyu

答えて

0

あなたがリストボックスに項目を追加する前に重複を確認する必要があります。

protected void Page_Load(object sender, EventArgs e) 
    { 
     BindData(); 
    } 

    private void BindData() 
    { 
     List<string> values = ViewState["Colours"] as List<string>; 

     if (values == null) 
     { 
      values = new List<string> 
      { 
       "red", 
       "green", 
       "blue" 
      }; 
     } 

     ViewState["Colours"] = values; 

     colours.DataSource = values; 
     colours.DataBind(); 
    } 

    protected void btnAddToListBox_Click(object sender, EventArgs e) 
    { 
     List<string> values = ViewState["Colours"] as List<string>; 
     string newColour = txtNewColour.Text; 
     bool exists = false; 

     values.ForEach(i => 
      { 
       if (i == newColour) 
        exists = true; 
      }); 

     if(!exists) 
     { 
      values.Add(txtNewColour.Text); 
      this.DataBind(); 
     } 
    } 
+0

ビッグ質問... – Gohyu

+0

私は理解していない、何をすべきかもしかして? –

関連する問題