Export (0) Print
Expand All

DataGrid.AutoGenerateColumns Property

Gets or sets a value that indicates whether BoundColumn objects are automatically created and displayed in the DataGrid control for each field in the data source.

[Visual Basic]
Public Overridable Property AutoGenerateColumns As Boolean
[C#]
public virtual bool AutoGenerateColumns {get; set;}
[C++]
public: __property virtual bool get_AutoGenerateColumns();
public: __property virtual void set_AutoGenerateColumns(bool);
[JScript]
public function get AutoGenerateColumns() : Boolean;
public function set AutoGenerateColumns(Boolean);

Property Value

true if BoundColumn objects are automatically created and displayed; otherwise, false. The default value is true.

Remarks

Use this property to automatically create a BoundColumn object for each field in the data source. Each field is then rendered as a column in the DataGrid control in the order that the fields appear in the data source.

Not all data types can be bound to the DataGrid control. If a field contains an unsupported data type, a column is not created for that field. If the data source only contains one column with an unsupported data type, an exception is thrown. The following table shows the data types that can be bound to the control.

Date Type Description
Primitives A primitive data type, such as System.Int32, Char, Double, and so on. For a complete list, see Type.IsPrimitive.
String A System.String object.
DateTime A System.DateTime object.
Decimal A System.Decimal object.
Note   Explicitly declared columns may be used in conjunction with auto-generated columns. When using both, explicitly declared columns will be rendered first, followed by the auto-generated columns. Auto-generated columns are not added to the Columns collection.

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

DataGrid Class | DataGrid Members | System.Web.UI.WebControls Namespace | BoundColumn | Columns | Type.IsPrimitive | System.String | System.DateTime | System.Decimal

Show:
© 2014 Microsoft