Skip to main content
A newer version of this page is available. .

How to: Create an ASPxGridView at Runtime

This example demonstrates how to create and initialize ASPxGridView at runtime.

using DevExpress.Web;
...
protected void Page_Load(object sender, EventArgs e)  {
     ASPxGridView grid1 = new ASPxGridView();
     grid1.ID = "grid1";
     grid1.AutoGenerateColumns = false;
     grid1.DataSourceID = "SqlDataSource1";
     grid1.KeyFieldName = "ProductID";
     grid1.Columns.AddRange(new GridViewDataColumn[]{
          new GridViewDataColumn { FieldName="ProductID", ReadOnly = true, VisibleIndex = 0},
          new GridViewDataColumn() { FieldName = "ProductName", VisibleIndex = 1 },
          new GridViewDataColumn() { FieldName = "UnitPrice", VisibleIndex = 2 },
     });
     Page.Form.Controls.Add(grid1);
}