Generating Columns For An SPGridView With LINQ (Extension Method)

More a small development note for myself since I generally end up using all the columns in a list when developing with SPGridView’s.

[csharp]
private static void GenerateColumns(this SPGridView gridView, SPList list )
{
gridView.AutoGenerateColumns = false;
foreach( var column in from string fieldname in list.DefaultView.ViewFields
select list.Fields.GetFieldByInternalName( fieldname )
into field
select new BoundField
{
DataField = field.StaticName,
HeaderText = field.Title
} )
{
gridView.Columns.Add( column );
}
}

[/csharp]

Share

Leave a Reply

Your email address will not be published. Required fields are marked *