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
115
Working with multi-column WebDataGrid - dynamic column labels
posted

I am converting a WinForms datagrid to Web and have had a few issues with this.  I am displaying a range of dates as columns and then jobs on those dates.  In this case I have set up 3 groups :- General, Week 1 and Week 2.  Under Week 1 and Week 2 I have the individual days.  In the markup these are simply columns within the group with their header text set to 'Day 1', 'day ' and so on. 

In the code behind I have implemented the gridReport_InitializeRow function as there doesn't appear to be an initialiseLayout as there is in WinForms.  I then check for row 1 and use the following code to set the label for each of the day columns

Dim group As GroupField = gridReport.Columns("Week 1")
For index As Integer = 0 To 6
   Dim column As GridField = group.Columns(index)
   column.Header.Text = day.ToString("ddd dd")
   day.AddDays(1)
Next

I thought this would work but when displayed my column headings are still the original values?  Any thoughts welcome

Parents
No Data
Reply
  • 1660
    Offline posted

    Hello Chris, 

    There is no equivalent to the InitializeLayout event in our WebForms controls, instead what I recommend you is using the PageLoad event with an if statement to see if it isn’t a PostBack and then create the columns there, this would ensure that the columns are created only once and would prevent exception that is caused by duplicate keys. 

    I have prepared a small sample that creates the columns of the WebDataGrid dynamically and organizes them in GroupFields. Below you can find the sample as well as a screenshot that demonstrates how the grid looks with the GroupFields added.

    Please test the sample on your side and let me know if you have any questions. 

    Regards,
    Ivan Kitanov

    DynamicGroupFields.zip

Children
No Data