SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to search through my lists. And show it on a repeater control. On my dropdown i got 3 options, (All, List1 and List2). But my If statement wont work. The else is working fine, but it hangs when i click on "All". Any suggestions? My code below.

        using (SPSite site = new SPSite("http://knowitintranet:9797/sites/News"))
            SPWeb web = SPContext.Current.Web;

            if (DropDownListNewsFeed.SelectedItem.Value == "All")
                SPSiteDataQuery query = new SPSiteDataQuery();
                    query.Lists = "<Lists " +
                                  "ServerTemplate=\"10000\"" +
                                  "ServerTemplate=\"10001\"" +
                                  "ServerTemplate=\"10002\">" +

                query.Query = string.Format("<OrderBy><FieldRef Name='Modified' Ascending='FALSE'></FieldRef></OrderBy>");
                query.Webs = "<Webs Scope=\"SiteCollection\" />";

                query.RowLimit = 10;

                DataTable dataTable = web.GetSiteData(query);

                RepeaterNewsFeed.DataSource = dataTable;

                SPList list = web.Lists.TryGetList(DropDownListNewsFeed.SelectedItem.Value);

                SPQuery query = new SPQuery();
                query.Query = "<OrderBy><FieldRef Name='Modified' Ascending='FALSE' /></OrderBy>";
                query.RowLimit = 10;

                SPListItemCollection items = list.GetItems(query);

                RepeaterNewsFeed.DataSource = items;
share|improve this question
Are you assigning string.Format("<OrderBy><FieldRef Name='Modified' Ascending='FALSE'></FieldRef></OrderBy>"); this to query.Query??? – Flowerking Jan 29 '13 at 14:21
@Flowerking . My bad, don't know how it disappeared xD My bad! – Kristian Salov Jan 29 '13 at 14:23
What do you mean by "Hangs", did you manage to debug this, do you get any exceptions? – Flowerking Jan 29 '13 at 14:26
@Flowerking. Well it really don't hangs. It just don't give me any output when i select "All" in my dropdownselect. But when i select list1 or list2, it shows output without problems. I don't even get any exceptions and i've tried to debug, doesn't give me any answer.. – Kristian Salov Jan 29 '13 at 14:28
@Flowerking, updated the code – Kristian Salov Jan 29 '13 at 14:30

I don't see anything wrong with your code, but you should really check to see if this works..

What you get from web.Lists.TryGetList("Staff News").ID is a guid wrapped in {} like {Some Guid} eg. {700de2ad-9bde-432b-b7a7-11fdc5168c4b} So if you can take these Guids and strip the curly braces out before assigning them inside the xml for "<List ID=" + web.Lists.TryGetList("Staff News").ID + " />". As this can cause problems with caml queries.

Just add .ToString() to the end as shown:

"<List ID=" + web.Lists.TryGetList("Staff News").ID.ToString()" />
share|improve this answer
So how should i change the code? Quite confused right now hehe.. It would be nice if you tried to take my code and change it here? – Kristian Salov Jan 29 '13 at 14:44
Updated the code, do you mean like that? – Kristian Salov Jan 29 '13 at 14:46
web.Lists.TryGetList("Staff News").ID will return guid.. change it to return string as shown. This will work. – Flowerking Jan 29 '13 at 14:49
"Redundant 'Object.ToString()' call for value type." is what i get now and i still don't get a output ;/ – Kristian Salov Jan 29 '13 at 14:54
Thats strange! Object.ToString() for value type? I really don't get it. Can you try using the list ID's directly as you have shown just now and try to see if it works? Like I said I really don't see anything wrong with your code (unless I am wrong :( ) – Flowerking Jan 29 '13 at 15:08

Your Answer


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.