Databases Reference
In-Depth Information
By default, the GridView control generates a BoundField for every column in the table.
Instead, you want to replace its columns generator with the one provided by Dynamic
Data as shown in Listing 1.15.
LISTING 1.15
DefaultAutoFieldGenerator Sample (Code-Behind)
using System;
using System.Web.DynamicData;
namespace WebApplication.Samples.Ch01.FieldGenerator
{
public partial class SamplePage : System.Web.UI.Page
{
protected void Page_Init(object sender, EventArgs e)
{
MetaTable table = Global.DefaultModel.GetTable(this.dataSource.EntitySetName);
this.gridView.SetMetaTable(table);
this.gridView.ColumnsGenerator = new DefaultAutoFieldGenerator(table);
}
}
}
Note that DefaultAutoFieldGenerator class, despite of its somewhat misleading name, is
actually provided by Dynamic Data. Based on columns of the specified MetaTable , it
generates DynamicField instances for a GridView or DetailsView control that use it. Figure
1.14 shows the resulting page based on this code. Notice that the UnitsInStock column is
using the Integer_Edit field template.
 
Search WWH ::




Custom Search