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.v19.2.dll
Declaration
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.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/aspxgridview-how-to-add-a-column-if-the-autogeneratecolumns-property-is-set-to-true-e3587
<%@ 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>
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the AutoGenerateColumns property.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.