Hi
We're using the below code to build the grid at the runtime
Partial Class _Default Inherits System.Web.UI.Page
Public Class personXXX Public name As String Public age As Int16 Public gender As String Public status As Boolean Public State As String End Class
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load BuildGrid() End Sub
Private Sub BuildGrid()
Dim dataTab As New DataTable Dim colDB As New DataColumn Dim objRow As DataRow
WebDataGrid1.Rows.Clear()
colDB = New DataColumn("RowID", Type.GetType("System.Int16")) dataTab.Columns.Add(colDB)
colDB = New DataColumn("Name", Type.GetType("System.String")) dataTab.Columns.Add(colDB)
colDB = New DataColumn("Age", Type.GetType("System.Int16")) dataTab.Columns.Add(colDB)
colDB = New DataColumn("Gender", Type.GetType("System.String")) dataTab.Columns.Add(colDB)
colDB = New DataColumn("Status", Type.GetType("System.Boolean")) dataTab.Columns.Add(colDB)
colDB = New DataColumn("State", Type.GetType("System.String")) dataTab.Columns.Add(colDB)
Dim per1 As New personXXX With { _ .name = "Eliza", _ .age = 27, _ .gender = "Female", _ .State = "CA", _ .status = True } Dim per2 As New personXXX With { _ .name = "Sarah", _ .age = 22, _ .gender = "Female", _ .State = "GA", _ .status = True } Dim per3 As New personXXX With { _ .name = "ema", _ .age = 22, _ .gender = "Female", _ .State = "MD", _ .status = False } Dim per4 As New personXXX With { _ .name = "rachel", _ .age = 20, _ .gender = "Female", _ .State = "MD", _ .status = True } Dim per6 As New personXXX With { _ .name = "jim", _ .age = 22, _ .gender = "Male", _ .State = "MD", _ .status = True } Dim per5 As New personXXX With { _ .name = "jack", _ .age = 32, _ .gender = "Male", _ .State = "CA", _ .status = True }
WebDataGrid1.AutoGenerateColumns = True
Dim personArr As personXXX() = {New personXXX(), per1, per2, per3, per4, per5, per6}
For introw = 1 To 6 objRow = dataTab.NewRow() objRow(0) = introw objRow(1) = personArr(introw).name.ToString objRow(2) = Integer.Parse(personArr(introw).age) objRow(3) = personArr(introw).gender.ToString objRow(4) = personArr(introw).status objRow(5) = personArr(introw).State dataTab.Rows.Add(objRow) Next WebDataGrid1.DataSource = dataTab WebDataGrid1.DataBind() End Sub
End Class
The 'WebDataGrid1.Columns' returns nothing, how to get the column collection object? we need to get the column object to set column width, change the column header text and CSS class.
Any help?
Regards, Karthik
Hello Karthik ,
I’m just following up to see if you’ve been able to resolve your issue. If you have any questions or concerns or if you need further assistance please let me know.
Best Regards,
Maya Kirova
Developer Support Engineer
Infragistics, Inc.
http://es.infragistics.com/support
Thank you for posting in our forum.
It seems that you autogenerate the columns: WebDataGrid1.AutoGenerateColumns = True
When the columns in the grid are autogenerated the Columns collections would be empty.
For more information please refer to the following post:
http://es.infragistics.com/community/forums/p/20173/73134.aspx#73134
To have them in your Columns collection you have to either define them in the designer or add them in the columns collection manually in code behind. In both cases AutoGenerateColumns should be set to false.
If you want to have them autogenerated then you could still access then from the items in the rows. For example: WebDataGrid1.Rows[0].Item[0].Column
Let me know if you have any questions.
Developer Support Engineer II