Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

SPSiteDataQuery not bringing any value for the 'AssignedTo' field

$
0
0
I'm trying to create a web part that reads all Tasks lists in a given web (and it's sub webs) bringing some information that i'll have displayed on a GridView. I need to bring only the first/parent item of each list to display the task's Title, Start date, Due date, Status, who's it assigned to and the % of completion.

To do that, I've created a GridView on my ascx file

<asp:GridView ID="gridTasks" AutoGenerateColumns="true" runat="server" ShowHeader="true" />

And for the data, i'm using the SPSiteDataQuery object to retrieve the data i need

SPSiteDataQuery query = new SPSiteDataQuery();
query.Webs = "<Webs Scope='Recursive'>";
query.Lists = "<Lists ServerTemplate='171'/>";
query.ViewFields = "<FieldRef Name='Title' Type='Text'/>";
query.ViewFields += "<FieldRef Name='StartDate' />";
query.ViewFields += "<FieldRef Name='DueDate' />";
query.ViewFields += "<FieldRef Name='Status' />";
query.ViewFields += "<FieldRef Name='AssignedTo' Type='User' Nullable='TRUE' />";
query.ViewFields += "<FieldRef Name='PercentComplete' Type='Number' Nullable='TRUE' />";
query.Query = "<Where><IsNull><FieldRef Name='ParentID' /></IsNull></Where>";
query.Query += "<OrderBy><FieldRef Name='Title' Ascending='True'/></OrderBy>";
gridTasks.DataSource = web.GetSiteData(query);gridTasks.DataBind();

When i run this code, it brings me data, but with a issue. Checking the grid view after it's filled with the data, i saw that the column 'AssignedTo' is empty, it's not bringing any information.

That is (for me) very strange, because if i run the following code and debug it, i can get the value of the AssignedTo value is being passed to the String variable .

foreach (SPListItem item in web.Lists["Tasks"].Items){
     String who = Convert.ToString(item["AssignedTo"]);
}

Is this a common issue? Is there anything different i need to do to with my SPSiteDataQuery or is there any other way to achieve what i need to do?

Thanks in advance.

Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>