list items moving one list to another list
<script type="text/javascript">
function ShowSelectedItems() {
var ctx = SP.ClientContext.get_current();
var items = SP.ListOperation.Selection.getSelectedItems(ctx);
//alert(items);
var myItems = '';
var i;
for (i in items) {
myItems += '|' + items[i].id;
}
document.getElementById("<%=inpHide.ClientID %>").value = myItems;
return myItems;
}
</script>
<table width="1000"><tr><td align="center"><asp:Button ID="Activate" runat="server"
Text="Activate" onclick="Activate_Click" OnClientClick="return ShowSelectedItems()"
/>
protected void Activate_Click(object sender, EventArgs e)
{
var url = SPContext.Current.Web.Url;
int i = 1;
string a = inpHide.Value;
string[] empidvalues = a.Split('|');
int count = empidvalues.Length;
for (i = 1; i < count; i++)
{
int id = Convert.ToInt32(empidvalues[i]);
//SPSite site = new SPSite("http://sitename:7979/Team");
SPSite site = new SPSite(url);
SPWeb web = site.OpenWeb();
web.AllowUnsafeUpdates = true;
SPList deactivatedteamlist = web.Lists["DeactivatedTeams"];
DataTable table = deactivatedteamlist.GetItems(deactivatedteamlist.DefaultView).GetDataTable();
SPList activatedteamlist = web.Lists["Team"];
SPListItemCollection collection = deactivatedteamlist.GetItems();
SPListItem item = collection.GetItemById(id);
SPListItem listitem = activatedteamlist.Items.Add();
listitem["Team Name"] = item["TeamName"].ToString();
string location = item["Location"].ToString();
string[] locations = location.Split(',');
//listitem["Location"] = location;
listitem["ParentLocation"] = locations[0].ToString();
listitem["ChildLocation"] = locations[1].ToString();
listitem["Department"] = item["Department"].ToString();
listitem["Profiles"] = item["Title"].ToString();
// listitem["Description"] = item["Description"].ToString();
listitem.Update();
item.Delete();
i++;
}
}
No comments:
Post a Comment