System.Web.UI.WebControls Namespace GridView Class
.NET Framework version 2.0
Sets or retrieves a value specifying whether BoundField objects are automatically created and displayed in the GridView control for each field in the data source.
Inline |
<asp:gridview autogeneratecolumns = true | false ... > |
Script |
GridView.AutoGenerateColumns [ = true | false ] |
This property accepts or returns only a boolean value: true if BoundField objects are automatically created and displayed; otherwise, false. Default value is true.
Use this property to automatically create a BoundField object for each field in the data source. Each field is then rendered as a column in the GridView control in the order that the fields appear in the data source.
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.
The following examples illustrate using automatically generated BoundField objects for each field in the data source. Note that there really is no need to explicitly declare the AutoGenerateColumns property, as it defaults to true if not specified.
The following example demonstrates how to disable the AutoGenerateColumns property to enable using other column types for each specified field in the data source.
<asp:gridview id = "myGrid" runat = "server" ... >
datasourceid = "plans"
autogeneratecolumns=false ... >
<columns>
<asp:imagefield dataimageurlfield = "PlanID"
dataimageurlformatstring = "~/shared/images/plans/thumbs/{0}.jpg"
dataalternatetextfield = "Model"
readonly = "true" />
<asp:templatefield>
<headertemplate>
Choose your dream home
</headertemplate>
<itemtemplate>
<asp:linkbutton runat = "server" commandname = "select"
text='<%# Eval ( "Model" ) %>' />
</itemtemplate>
</asp:templatefield>
<asp:boundfield headertext = "Avg. Cost To Build"
datafield = "Cost"
htmlencode=false
dataformatstring = "{0:c}"
rowstyle-horizontalalign = "right" />
</columns>
</asp:gridview>
GridView Members BoundField ButtonField CheckBoxField CommandField HyperLinkField ImageField TemplateField