We're using the Infragistics 2010.3 ASP.NET version controls and having issues in accessing the column properties (such as column count and setting a column width).
We're using a datasource to build the grid data and attaching the datatable to the grid.
In the ASPX page, the grid is declared as below
<ig:WebDataGrid ID="UGData" runat="server" Height="350px" Width="767px" />
In the Code Behind page, the below snippet attaches the databtable to the grid
Dim dt As New DataTable()
UGData.AutoGenerateColumns = True
dt.Columns.Add("Column 1", Type.[GetType]("System.Double"))
dt.Columns.Add("Column 2")
dt.Columns.Add("Column 3")
Dim dr As DataRow = dt.NewRow()
For i As Integer = 1 To 5000
dr = dt.NewRow()
dr(0) = i
dr(1) = DateTime.Today.AddDays(i)
dr(2) = "Test " & i.ToString()
dr(3) = (i Mod 2 = 0)
dt.Rows.Add(dr)
Next
UGData.DataSource = dt
UGData.DataBind()
For some reason, the 'UGData.Columncount' property always returns 0. Also, the I can't set the column width using 'UGData.Columns(0).Width = Unit.Pixel(100)'
whats wrong?
Hi,
Let us know if you need further assistance with this.
Regards,
Lyuba
Developer Support Engineer
Infragistics
www.infragistics.com/support
If you would like to access a column you should add it as a BoundDataField in the Columns collection and you should set AutoGenerateColumns to false.
Lyuba,
Your suggestion works only if the grid has at least one record. If the grid doesn't have any record, the column collections returns nothing and can't get the column count or set the column width.
In the classic UltraGrid, we can get the columns count and set the column width even though there are no records in the grid.
Is there a another way to get the 'autogenerated' columns count and setting the column width?
Regards, Karthik
The Columns collection contains only the columns that are defined in the columns collection in the aspx or that are added to it in the code behind, and it doesn’t contain the autogenerated ones.
If you need to change some property of an autopgenerated column you can access it via the cell:
WebDataGrid1.Rows[0].Items[colIndex].Column.
Hope this helps.