Prasad Bolla's SharePoint Blog

Click Here to go through the Interesting posts within my Blog.

Click Here to go through the new posts in my blog.

Thursday, December 01, 2011

Getting Data from Subsites to TopSite With Null Checking which is getting binded with SpGridView Using Server Side Linq

try
{
string Title = string.Empty;
string Status = string.Empty;
string AssignedTo = string.Empty;
string WebTitle = string.Empty;
var query = from SPWeb subWeb in SPContext.Current.Web.GetSubwebsForCurrentUser()
from SPListItem item in subWeb.Lists["Tasks"].Items
orderby item["ID"] descending
select new
{
Title=item["Title"].ToString(),
Status=(item["Status"]==null) ? "Data UnAvailable" : item["Status"].ToString(),
Priority = (item["Priority"] == null) ? "Data UnAvailable" : item["Status"].ToString(),
AssignedTo = (item["AssignedTo"] == null) ? "Data UnAvailable" : item["AssignedTo"].ToString().Substring(item["AssignedTo"].ToString().LastIndexOf("\\") + 1),
WebTitle=subWeb.Title
};
if (query.Count() > 0)
{
sgvTest.DataSource = query;
sgvTest.DataBind();
}
}
catch (Exception ex)
{
this.Controls.Add(new LiteralControl(ex.ToString()));
}

No comments:

Post a Comment