ascx.cs
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using System.Data;
namespace SampleSPDataQuery.CorporateAnnouncements
{
public partial class CorporateAnnouncementsUserControl : UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
BindGridDetails();
}
public void BindGridDetails()
{
try
{
SPUser oCuser= SPContext.Current.Web.CurrentUser ;
using (SPSite osite = new SPSite(SPContext.Current.Site.ID))
{
using (SPWeb oweb = osite.OpenWeb())
{
SPSiteDataQuery ositeDataQuery = new SPSiteDataQuery();
ositeDataQuery.Lists = "<Lists ServerTemplate='104'/>";
ositeDataQuery.Query = "<Where><Eq><FieldRef Name='user' /><Value Type='User'>" + oCuser.LoginName + "</Value></Eq></Where>";
ositeDataQuery.Webs = "<Webs Scope='SiteCollection' />";
ositeDataQuery.ViewFields = "<FieldRef Name='Title' /><FieldRef Name='ID' /><FieldRef Name='Body' /><FieldRef Name='FileRef' /><FieldRef Name='EncodedAbsUrl' /><FieldRef Name='FileDirRef' />";
ositeDataQuery.RowLimit = 10;
DataTable odt = oweb.GetSiteData(ositeDataQuery);
grdAnnouncements.DataSource = odt;
grdAnnouncements.DataBind();
}
}
}
catch (Exception ex)
{
lblError.Text = ex.Message;
}
}
protected void grdAnnouncements_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblFileDirRef = (Label)e.Row.FindControl("lblFileDirRef");
Label lblItemID = (Label)e.Row.FindControl("lblItemID");
HyperLink lnkTitle = (HyperLink)e.Row.FindControl("lnkTitle");
lnkTitle.NavigateUrl = lnkTitle.NavigateUrl + lblFileDirRef.Text.Split('#')[1] + "/DispForm.aspx?ID=" + lblItemID.Text ;
lblFileDirRef.Visible = false;
lblItemID.Visible = false;
}
}
}
}
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using System.Data;
namespace SampleSPDataQuery.CorporateAnnouncements
{
public partial class CorporateAnnouncementsUserControl : UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
BindGridDetails();
}
public void BindGridDetails()
{
try
{
SPUser oCuser= SPContext.Current.Web.CurrentUser ;
using (SPSite osite = new SPSite(SPContext.Current.Site.ID))
{
using (SPWeb oweb = osite.OpenWeb())
{
SPSiteDataQuery ositeDataQuery = new SPSiteDataQuery();
ositeDataQuery.Lists = "<Lists ServerTemplate='104'/>";
ositeDataQuery.Query = "<Where><Eq><FieldRef Name='user' /><Value Type='User'>" + oCuser.LoginName + "</Value></Eq></Where>";
ositeDataQuery.Webs = "<Webs Scope='SiteCollection' />";
ositeDataQuery.ViewFields = "<FieldRef Name='Title' /><FieldRef Name='ID' /><FieldRef Name='Body' /><FieldRef Name='FileRef' /><FieldRef Name='EncodedAbsUrl' /><FieldRef Name='FileDirRef' />";
ositeDataQuery.RowLimit = 10;
DataTable odt = oweb.GetSiteData(ositeDataQuery);
grdAnnouncements.DataSource = odt;
grdAnnouncements.DataBind();
}
}
}
catch (Exception ex)
{
lblError.Text = ex.Message;
}
}
protected void grdAnnouncements_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblFileDirRef = (Label)e.Row.FindControl("lblFileDirRef");
Label lblItemID = (Label)e.Row.FindControl("lblItemID");
HyperLink lnkTitle = (HyperLink)e.Row.FindControl("lnkTitle");
lnkTitle.NavigateUrl = lnkTitle.NavigateUrl + lblFileDirRef.Text.Split('#')[1] + "/DispForm.aspx?ID=" + lblItemID.Text ;
lblFileDirRef.Visible = false;
lblItemID.Visible = false;
}
}
}
}
No comments:
Post a Comment