DataGrid dynamic columns / firing events

A

Abelardo Vacca

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
 
P

Phillip Williams

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top