Create multi-row gridview Header with buttons in header

I found a few articles , that try to create multi-row gridview Header
 
All solutions suggest to create extra DataViewRow(s) of a type DataControlRowType.Header on RowDataBound event.
However on Postback DataBind usually is not called, and so RowDataBound event will not occur.
It means that the second header will not be recreated on Postback -not good.
 
Discussion GridView – trouble with double header row has a suggestion to use rowcreated event  that should be called during initial DataBind and during subsequent postback.
 
Using RowCreated event to create additional rows in header works perfectly for me.
 
Note that RowCreated event is called within parent LoadViewState event, but before LoadViewState for individual row.
So not all info could be available at that time.
Alternatively it can be tried on page_load time on PostBack when state has been loaded already as suggested in Access Dynamic GridView ItemTemplate after postback discussion.
I strongly recommend to read a great atricle: TRULY Understanding Dynamic Controls  -Parts 1-4 and avoid using dynamic controls if possible.
Advertisements