Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
589
How to get the Columncount value and set the column width
posted

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?

Parents
No Data
Reply
  • 6748
    Suggested Answer
    posted

    Hi,

     

    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.

     

    Regards,

    Lyuba

    Developer Support Engineer

    Infragistics

    www.infragistics.com/support

     

     

Children