DetailsView autogeneraterows property

The AutoGenerateRows property of the detailsView control specifies that the row of fields from a data source should be generated automatically. If the AutoGenerateRows property value is set to true, the detailsView control displays row of fields for each record in the data source automatically.

If we do not want to display all the fields retrieved from the data source, we set the AutoGenerateRows property value to false. In this case, we need to declare boundfield elements or TemplateField elements which corresponds to the fields to be displayed in the DetailsView control.

The following code demonstrates how to use AutoGenerateRows property in a DetailsView control. We have set the AutoGenerateRows property to true. All the fields in the sample table are displayed in the DetailsView control.

<asp:DetailsView ID="DetailsView1" runat="server"  
   AutoGenerateRows="true" 
   AllowPaging="true" DataKeyNames="Code" 
   DataSourceID="MyDataSource"   
   AutoGenerateInsertButton="true"   
   AutoGenerateEditButton="true">
   </asp:DetailsView>
<asp:SqlDataSource ID="MyDataSource"  
ConnectionString="<%$Connectionstrings:ERPConnectionString%>"
SelectCommand="SELECT * FROM Sample" 
UpdateCommand="Update SAMPLE SET Name=@Name,description=@description Where Code=@Code"
DeleteCommand="Delete SAMPLE Where Code=@Code" 
InsertCommand="Insert SAMPLE(Code,Name,description) VALUES(@Code,@Name,@description)"
runat="server"/>


output of DetailsView control with AutoGenerateRows property