At my TechEd talk last week I showed Visual Studio 2008 extensions for SharePoint 1.3 and I demo’d creating a simple web part that shows data from a SharePoint list in a grid. I also showed command line builds which is one of the features we added in VSeWSS 1.3 and I showed the SPDisposeCheck tool.
For the demos I used the WSS Developer VPC which is available here. I uninstalled the VSeWSS 1.2 that comes on that image and installed the VSeWSS 1.3 from here. I also installed SPDisposeCheck from here.
So that’s my machine image to which I also created a sample Employees list and a Projects list in the default SharePoint site. Here’s the code that I used in the first demo. Pretty simple stuff.
public class WebPart1 : System.Web.UI.WebControls.WebParts.WebPart
protected override void CreateChildControls()
SPGridView customerGridView = new SPGridView();
SPWeb web = SPContext.Current.Web;
SPList list = web.Lists[“Employees”];
SPQuery query = new SPQuery(list.DefaultView);
query.Query = “<Where><Eq><FieldRef Name=’JobTitle’ /><Value Type=’Text’>SDE</Value></Eq></Where>”;
SPListItemCollection items = list.GetItems(query);
customerGridView.DataSource = items.GetDataTable();
private void AutoAddColumns(SPGridView gridView, SPList list)
gridView.AutoGenerateColumns = false;
foreach (string fieldname in list.DefaultView.ViewFields)
SPField field = list.Fields.GetFieldByInternalName(fieldname);
BoundField column = new BoundField();
column.DataField = field.StaticName;
column.HeaderText = field.Title;