Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

How do i do so i can work on multiple lists? This works if i'm working with one list. (SPSiteDataQuery)

            SPWeb web = SPContext.Current.Web;

            SPList myList = web.Lists["Staff News"];

            Guid listItemId = new Guid(HiddenFieldID.Value);

            SPListItem itemToUpdate = myList.GetItemByUniqueId(listItemId);

            TextBox textBoxNickname = (TextBox)DetailsViewShowNews.FindControl("TextBoxNickname");
            TextBox textBoxComment = (TextBox)DetailsViewShowNews.FindControl("TextBoxComment");

            if(itemToUpdate != null)
            {
                itemToUpdate["Nickname"] = textBoxNickname.Text;
                itemToUpdate["Comments1"] = textBoxComment.Text;


                textBoxComment.Text = string.Empty;
                textBoxNickname.Text = string.Empty;

                itemToUpdate.Update();
            }
share|improve this question
add comment

1 Answer 1

You could just iterate through a list of lists in a foreach loop.

foreach (SPList list in web.Lists)
{
  // Do stuff
}

Or

var listOfLists = new List<SPList>();
listOfLists.Add(web.Lists["List 1"]);
listOfLists.Add(web.Lists["List 1"]);
foreach (SPList list in listOfLists)
{
  // Do stuff
}
share|improve this answer
    
i get Value does not fall within the expected range –  Martin Feb 16 '13 at 16:28
    
SPSiteDataQuery query = new SPSiteDataQuery(); query.Lists = "<Lists>" + "<List ID=" + web.Lists.TryGetList("StaffNews").ID.ToString() + " />" + "<List ID=" + web.Lists.TryGetList("CompanyNews").ID.ToString() + " />" + "<List ID=" + web.Lists.TryGetList("ManagementNews").ID.ToString() + " />" +"</Lists>"; Guid listItemId = new Guid(HiddenFieldID.Value); foreach (SPList list in web.Lists) {SPListItem itemToUpdate = list.GetItemByUniqueId(listItemId); itemToUpdate["Nickname"] = TextBoxName.Text; itemToUpdate["_Comments"] = TextBoxComment.Text; itemToUpdate.Update(); } –  Martin Feb 16 '13 at 16:29
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.