Skip to content

DevExpress-Examples/asp-net-web-forms-grid-add-column-to-autogenerated-columns

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Grid View for ASP.NET Web Forms - How to add a column if the AutoGenerateColumns property is set to true

This example demonstrates how to add a column to the grid when the AutoGenerateColumns property is enabled.

addColumn

Overview

When the AutoGenerateColumns property is set to true, handle the DataBound event to add a column to the Grid View control. Before you add a column, check whether this column already exists to avoid duplicate columns.

<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="True" 
    KeyFieldName="CategoryID" ondatabound="ASPxGridView1_DataBound">
</dx:ASPxGridView>
protected void ASPxGridView1_DataBound(object sender, EventArgs e) {
    if (grid.Columns.IndexOf(grid.Columns["CommandColumn"]) != -1)
        return;
    GridViewCommandColumn col = new GridViewCommandColumn();
    col.Name = "CommandColumn";
    // ...
    grid.Columns.Add(col);
}

Files to Review

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

About

Add a column to the grid when the AutoGenerateColumns property is enabled.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •