RadGrid for ASP.NET

RadGrid Send comments on this topic.
AutoGenerateColumns Property
See Also  Example
Telerik.WebControls Namespace > RadGrid Class : AutoGenerateColumns Property


Gets or sets a value indicating whether bound fields are automatically created for each field in the data source.   

 

Namespace: Telerik.WebControls
Assembly: RadGrid (in RadGrid.dll)

Syntax

Visual Basic (Declaration) 
Public Overridable Property AutoGenerateColumns As Boolean
Visual Basic (Usage)Copy Code
Dim instance As RadGrid
Dim value As Boolean
 
instance.AutoGenerateColumns = value
 
value = instance.AutoGenerateColumns
C# 
public virtual bool AutoGenerateColumns {get; set;}

Return Value

true to automatically create bound fields for each field in the data source; otherwise, false. The default is true.

Example

The following code example demonstrates how to use the AutoGenerateColumns property to automatically create bound columns in a Telerik RadGrid control for each field in the data source.
Visual BasicCopy Code
<%@ Page Language="VB" %>

<%@ Register Assembly="RadGrid.Net2" Namespace="Telerik.WebControls" TagPrefix="rad" %>

<!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>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <rad:RadGrid
            DataSourceID="SqlDataSource1"
            ID="RadGrid1"
            runat="server"
            AutoGenerateColumns="true"
            AllowSorting="true">
        </rad:RadGrid>
        <!-- This example uses Microsoft SQL Server And connects -->
        <!-- To the Northwind sample database. Use an ASP.NET -->
        <!-- expression To retrieve the connection String value -->
        <!-- from the Web.config file. -->
        <asp:SqlDataSource
            ID="SqlDataSource1"
            runat="server"
            ConnectionString="<<see cref="NorthwindConnectionString">$ ConnectionStrings</see>>"
            SelectCommand="SELECT [CustomerID], [ContactName], [CompanyName] FROM [Customers]">
        </asp:SqlDataSource>
    </div>
    
</body>
</html>

Remarks

When the AutoGenerateColumns property is set to true, an GridBoundColumn object is automatically created for each field in the data source. Each field is then displayed as a column in the Telerik RadGrid control in the order that the fields appear in the data source. This option provides a convenient way to display every field in the data source; however, you have limited control of how an automatically generated column field is displayed or behaves.

This set of columns can be accessed using the AutoGeneratedColumns collection.

Runtime auto-generated columns will always appear after the user-specified columns, unless the columns are ordered programmatically.

Instead of letting the Telerik RadGrid control automatically generate the column fields, you can manually define the column fields by setting the AutoGenerateColumns property to false and then creating a custom Columns collection. In addition to bound column fields, you can also display a button column, a check box column, a button column, a hyperlink column, an image column, or a column based on your own custom-defined template etc.

Requirements

Supported in: 3.0, 2.0, 1.1, 1.0 .NET Framework

See Also