Remove Duplicate Values From ListBox
Remove Duplicate Values two ListBoxes Using Without Database Connection in Asp.net C#
Foreach & if Conditions Using Remove Duplicate Values.
DEMO
First Add - New - Webform
Html Coding
C# Coding
Remove Duplicate Values two ListBoxes Using Without Database Connection in Asp.net C#
Foreach & if Conditions Using Remove Duplicate Values.
DEMO
First Add - New - Webform
Html Coding
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body style="height: 243px">
<form id="form1" runat="server">
<div>
<asp:ListBox ID="ListBox1" runat="server" Height="104px" OnSelectedIndexChanged="ListBox1_SelectedIndexChanged" Width="95px">
<asp:ListItem>AAA</asp:ListItem>
<asp:ListItem>BBB</asp:ListItem>
<asp:ListItem>CCC</asp:ListItem>
<asp:ListItem>DDD</asp:ListItem>
</asp:ListBox>
<asp:ListBox ID="ListBox2" runat="server" Height="142px" Width="110px" >
<asp:ListItem>AAA</asp:ListItem>
<asp:ListItem>BBB</asp:ListItem>
<asp:ListItem>CCC</asp:ListItem>
<asp:ListItem>DDD</asp:ListItem>
<asp:ListItem>EEE</asp:ListItem>
<asp:ListItem>FFF</asp:ListItem>
<asp:ListItem>GGG</asp:ListItem>
<asp:ListItem>EEE</asp:ListItem>
</asp:ListBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Remove Duplicates" />
</div>
</form>
</body>
</html>
C# Coding
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
foreach (ListItem LISTBOXES in ListBox1.Items)
{
if (ListBox2.Items.Contains(LISTBOXES) == true)
{
ListBox2.Items.Remove(LISTBOXES);
}
}
}
}
0 comments:
Post a Comment