using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
namespace MyCustomWebPart
{
[Guid("f66be37b-91f9-4e99-97dc-0e30f6eb44ff")]
public class MyCustomWebPart : System.Web.UI.WebControls.WebParts.WebPart
{
SPGridView myGrid;
public MyCustomWebPart()
{
}
protected override void CreateChildControls()
{
base.CreateChildControls();
SPDataSource SPDataSource1 = new SPDataSource();
try
{
SPSite mySite = SPContext.Current.Site;
SPWeb myWeb = mySite.OpenWeb();
//Using RunWithElevatedPrivileges
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite siteCollection = new SPSite(mySite.ID))
{
using (SPWeb web = siteCollection.OpenWeb(myWeb.ID))
{
myGrid = new SPGridView();
myGrid.AutoGenerateColumns = false;
BoundField ClientName = new BoundField();
ClientName.HeaderText = "Our Clients";
ClientName.DataField = "ClientsName";
myGrid.Columns.Add(ClientName);
SPList List = myWeb.Lists["Clients"];
SPDataSource1.List = List;
myGrid.DataSource = SPDataSource1;
myGrid.DataBind();
Controls.Add(myGrid);}}
});
}
catch { }}
}
}
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
namespace MyCustomWebPart
{
[Guid("f66be37b-91f9-4e99-97dc-0e30f6eb44ff")]
public class MyCustomWebPart : System.Web.UI.WebControls.WebParts.WebPart
{
SPGridView myGrid;
public MyCustomWebPart()
{
}
protected override void CreateChildControls()
{
base.CreateChildControls();
SPDataSource SPDataSource1 = new SPDataSource();
try
{
SPSite mySite = SPContext.Current.Site;
SPWeb myWeb = mySite.OpenWeb();
//Using RunWithElevatedPrivileges
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite siteCollection = new SPSite(mySite.ID))
{
using (SPWeb web = siteCollection.OpenWeb(myWeb.ID))
{
myGrid = new SPGridView();
myGrid.AutoGenerateColumns = false;
BoundField ClientName = new BoundField();
ClientName.HeaderText = "Our Clients";
ClientName.DataField = "ClientsName";
myGrid.Columns.Add(ClientName);
SPList List = myWeb.Lists["Clients"];
SPDataSource1.List = List;
myGrid.DataSource = SPDataSource1;
myGrid.DataBind();
Controls.Add(myGrid);}}
});
}
catch { }}
}
}
No comments:
Post a Comment