Please refer this code
<div>
<asp:ListBox ID="ListBox1" runat="server" Height="150">
<asp:ListItem Text="Apple" />
<asp:ListItem Text="Banana" />
<asp:ListItem Text="Orange" />
<asp:ListItem Text="Watermelon" />
<asp:ListItem Text="Strawberry" />
<asp:ListItem Text="Pineapple" />
</asp:ListBox>
<br />
<asp:ListBox ID="ListBox2" runat="server" Height="150">
<asp:ListItem Text="Apple" />
<asp:ListItem Text="Banana" />
<asp:ListItem Text="Watermelon" />
<asp:ListItem Text="Pineapple" />
</asp:ListBox>
<br />
<asp:ListBox ID="ListBox3" runat="server"></asp:ListBox>
<br />
<asp:Button Text="Move Same to 3 Listbox" OnClick="MoveSame" runat="server" />
</div>
HTML
protected void MoveSame(object sender, EventArgs e)
{
int listBox1Length = this.ListBox1.Items.Count;
int listBox2Length = this.ListBox2.Items.Count;
if (listBox1Length > listBox2Length)
{
this.SaveCommon(ListBox1, ListBox2);
}
if (listBox1Length < listBox2Length)
{
this.SaveCommon(ListBox2, ListBox1);
}
if (listBox1Length == listBox2Length)
{
this.SaveCommon(ListBox1, ListBox2);
}
}
private void SaveCommon(ListBox lb1, ListBox lb2)
{
foreach (ListItem item1 in lb2.Items)
{
foreach (ListItem item2 in lb2.Items)
{
if (item2.Text == item1.Text)
{
this.ListBox3.Items.Add(item2);
}
}
}
}