|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
DataGrid dynamic columns / firing eventsI have a DataGrid with columns build dynamically, the grid supports sorting. I create the columns OnInit so the sort event will fire when the headers are clicked. All this works fine. Now, one requirement is for the user to have the option of selecting predefined layouts for the DataGrid (differents columns in difference order) .... I added this feature using a dropdown list control with the layouts names on top of the page ... The problem is, since I am creating the DataGrid columns OnInit, the "selected layout" is NOT available yet (since the dropdown list control SelectedItemChanged event has not been handled yet ... it can't be handled before OnInit) The only way to create the correct columns for the DataGrid would be to create them after OnInit, but that way I won't have a DataGrid responsive to sorting events. Enter Catch-22. I even tried creating ALL possible columns during OnInit, and later on deleting the columns and recreating the correct ones (after learing the "selected layout"), but this creates a really weird behavior when sorting the columns - clicking one columns could result in sorting another columns - Any ideas? Could anyone confirm if I am correct by creating the DataGrid Columns OnInit, or is there any other way of creating these columns without losing the events? Thanks -- Abelardo Vacca You are correct in creating the datagrid columns OnInit. Separate the
routine that creates the datagrid in a separate function that is called from both OnInit and after you handled SelectedIndexChanged event. Persist an indicator of the layout change to redo it upon next postback in the OnInit event handling. Function DataGridCreate - if Session(“LayoutIndicatorsâ€) o retrieve those indicators - create the datagrid OnInit: - call the DataGridCreate OnSelectedIndexChanged - Save Session(“LayoutIndicatorsâ€) - Call the DataGridCreate Show quoteHide quote "Abelardo Vacca" wrote: > Hello, > > I have a DataGrid with columns build dynamically, the grid supports sorting. > I create the columns OnInit so the sort event will fire when the headers are > clicked. > > All this works fine. > > Now, one requirement is for the user to have the option of selecting > predefined layouts for the DataGrid (differents columns in difference order) > ... I added this feature using a dropdown list control with the layouts names > on top of the page ... > > The problem is, since I am creating the DataGrid columns OnInit, the > "selected layout" is NOT available yet (since the dropdown list control > SelectedItemChanged event has not been handled yet ... it can't be handled > before OnInit) > > The only way to create the correct columns for the DataGrid would be to > create them after OnInit, but that way I won't have a DataGrid responsive to > sorting events. > > Enter Catch-22. > > I even tried creating ALL possible columns during OnInit, and later on > deleting the columns and recreating the correct ones (after learing the > "selected layout"), but this creates a really weird behavior when sorting the > columns - clicking one columns could result in sorting another columns - > > Any ideas? Could anyone confirm if I am correct by creating the DataGrid > Columns OnInit, or is there any other way of creating these columns without > losing the events? > > Thanks > -- > Abelardo Vacca |
|||||||||||||||||||||||