Skip to main content
Tab

ASPxGridView.AutoGenerateColumns Property

Gets or sets whether columns are automatically created for all fields in the underlying data source.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v22.1.dll

Declaration

[DefaultValue(true)]
public bool AutoGenerateColumns { get; set; }

Property Value

Type Default Description
Boolean

true

true, to automatically create columns for all fields in the underlying data source; otherwise, false.

Remarks

The AutoGenerateColumns property specifies which data fields are rendered by the ASPxGridView. By default, this property is set to true. This forces the ASPxGridView to render each field from the data source as a column. The order of columns is the same as the order of fields in the data source.

You can also manually control which columns are to appear in the ASPxGridView by setting the AutoGenerateColumns property to false. In this case, you should manually add columns to the ASPxGridView.Columns collection.

Example

When the AutoGenerateColumns property is set to true, the only way to add a column to ASPxGridView is to handle the ASPxGridView.DataBound event. To avoid creating duplicate columns, it is necessary to add a condition that will check whether a column already exists.

View Example

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="DevExpress.Web.ASPxGridView.v11.1, Version=11.1.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.ASPxEditors.v11.1, Version=11.1.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>How to add a column if the AutoGenerateColumns property is set to true</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="True" DataSourceID="ds"
            KeyFieldName="CategoryID" ondatabound="ASPxGridView1_DataBound">
        </dx:ASPxGridView>
        <asp:AccessDataSource ID="ds" runat="server" DataFile="~/App_Data/nwind.mdb" SelectCommand="SELECT [CategoryID], [CategoryName], [Description] FROM [Categories]">
        </asp:AccessDataSource>
    </div>
    </form>
</body>
</html>
See Also