You can't use foreach statement on single item that should be a collection but you can use for loop for your solution.like
.aspx Page
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="envornment.aspx.cs" Inherits="TestApplication.envornment" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ListBox Id="lstboxSkill" runat="server" SelectionMode="Multiple">
<asp:ListItem Value="1" Text="ABC"></asp:ListItem>
<asp:ListItem Value="2" Text="XYZ"></asp:ListItem>
</asp:ListBox>
<asp:ImageButton ID="imgbtnMoveRightListBox" runat="server" ImageUrl="demo.gif"
onclick="imgbtnMoveRightListBox_Click" />
<asp:ListBox ID="lstBBoxSkill2" runat="server" SelectionMode="Multiple">
</asp:ListBox>
</form>
</body>
</html>
.cs page
using System;
using System.Web.UI.WebControls;
namespace TestApplication
{
public partial class envornment : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void imgbtnMoveRightListBox_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
for (int i = 0; i < lstboxSkill.Items.Count; i++)
{
if (lstboxSkill.Items[i].Selected)
{
lstBBoxSkill2.Items.Add(lstboxSkill.Items[i]);
}
}
}
}
}