Friday, March 27, 2009

Add a GridView to a sharepoint webpart

using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;


namespace samplewebpart
{
public class GridControl : WebPart
{
protected override void CreateChildControls()
{

GridView grdview = new GridView();
SPWeb web = SPContext.Current.Web;
SPList list = web.Lists["mylist"];
grdview.DataSource = list.Items.GetDataTable();
grdview.DataBind();
this.Controls.Add(grdview);


}
}
}

-Bharath Boddu

No comments:

Post a Comment