Articles in this section
Category / Section

How to add additional columns in GridDataBoundGrid?

1 min read

By default, the columns will be displayed as per the datasource that assigned to grid. In order to add unbound columns in the GridDataBoundGrid, the following steps can be used,

1.   Create GridBoundColumnsCollection to be added to grid and copies of all members in this collection.

2.   Create the Custom column and add it to the collection by using Add method.

3.   If you want to add the column at specified index, you can use Insert method.

4.   Bind the created column collection to GridDataBoundGrid column collection.

 

Code Snippet

C#

// Creates a column collection to be added to the grid.
GridBoundColumnsCollection columnCollection= (GridBoundColumnsCollection)this.gridDataBoundGrid1.Binder.InternalColumns.Clone();
 
// Creates the column to be added.
GridBoundColumn unboundColumn= new GridBoundColumn();
unboundColumn.HeaderText = "NewColumn";
unboundColumn.MappingName = "NewColumn";
 
// Adds the created column to the collection.
columnCollection.Add(unboundColumn);
 
//Insert the column at specified index.
columnCollection.Insert(2, unboundColumn);
 
// Binds the created column collections to the grid bound columns.
this.gridDataBoundGrid1.Binder.GridBoundColumns = columnCollection;

 

VB

' Creates a column collection to be added to the grid.
Dim columnCollection As GridBoundColumnsCollection = CType(Me.gridDataBoundGrid1.Binder.InternalColumns.Clone(), GridBoundColumnsCollection)
 
' Creates the column to be added.
Dim unboundColumn As New GridBoundColumn()
unboundColumn.HeaderText = "NewColumn"
unboundColumn.MappingName = "NewColumn"
 
' Adds the created column to the collection.
columnCollection.Add(unboundColumn)
 
'Insert the column at specified index.
columnCollection.Insert(2, unboundColumn)
 
' Binds the created column collections to the grid bound columns.
Me.gridDataBoundGrid1.Binder.GridBoundColumns = columnCollection

 

C:\Users\piruthiviraj.malaime\Desktop\img1.PNG

Sample Links

C#: AddingCustomColumns_CS

VB: AddingCustomColumns_VB

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied