The "DataGrid" object in ASP.NET provides developers with the ability to list data in a table-like structure. The DataGrid is similar to a table, but it has several functions and properties that give developers the tools to format the data. One option for programmers is the function to add columns to the DataGrid in the code. You can add one or several columns at one time to your web page's DataGrid object.
Define a new data column. This column is later added to the grid, but you need a data column object defined to set the format settings for the column. The following code creates a data column:
Dim column As DataColumn
Assign the data column's text header and data type. The column text defines the header, which is shown at the top of the column. The data type defines what type of data you can insert into the DataGrid's column. In this example, the "Customer Name" column is created and it contains a string. The following code creates the column's settings:
dc = New DataColumn("Customer Name", Type.GetType("System.String"))
Add the column to the DataGrid. The DataGrid has an "Add()" function that allows you to insert a new column dynamically. The following code adds the column created in step two to your DataGrid:
Save your code changes and open the page in your browser. The column is created in the grid with the "Customer Name" header text.
- Photo Credit red and green discs in a red grid image by nebari from Fotolia.com
How to Add Dynamic DataGrid Columns
A "DataGrid" is a .NET component that lets you display records of information for your readers. A DataGrid lets you display records...
How to Add a Data Grid Column
The C# data grid object provides a spreadsheet of information for users. The data grid can be used in desktop or website...
How to Hide DataGrid Columns
Datagrids are controls that hold data in grids like a spreadsheet. They can be used in both Windows forms and websites. The...
How to Insert Data in Grid View
GridView is a .NET Framework class. It allows you to display data items in columns in your database. You can insert new...
How to Calculate Columns in a MS DataGrid
Knowing how to calculate columns in a Data Grid View control using Microsoft Visual Basic.NET, or VB.NET, can save you time when...
How to Fix Columns in DataGrid
A "DataGrid" object is a Microsoft ASP.NET control that provides a spreadsheet layout on your software forms. The columns are automatically sized...
How to Add a DropDownList in DataGrid
Microsoft .NET Framework DataGrid control allows you to display rows of data tables. If you want to show a large amount of...
How to Add Columns and Rows in PowerPoint 2007
Microsoft PowerPoint software, part of the Microsoft Office Suite, offers a way to compile data, images and information into a slide show...