See attached example.
This very basically mimics what we are doing on our page. The problem here is that, while the cell images (for the individual rows) are retained (due to the .databind / row initialize being fired each time on Page_Load), the Header image that was created when the template data column was created does not reappear after postback.
The header (image) template needs to be able to be created programmatically on Load as the information about that image, etc is stored in the DB. How can I get the template data field's header template to re-appear on postback?
Is there a way to programmatically add the template to the grid (like you can with dataproviders) and have the grid retain those on postback and just "reference" the template like you do with the providers?
Hi greghendricks,
Thank you for posting in the community.
From what I can understand you need to dynamically instantiate a template for your WebDataGrid. I suggest that you refer to the following resources for more information and instructions on using programmatically created templates in WebDataGrid:
http://help.infragistics.com/Help/NetAdvantage/ASPNET/2011.1/CLR4.0/html/WebDataGrid_Column_Templates.html
http://help.infragistics.com/NetAdvantage/ASPNET/2011.1?page=WebDataGrid_Using_Item_Template.html
Note that when creating templates programmatically, they need to be reinstantiated on every postback (prefferably at the PreInit or Init stage).
Please let me know if this helps.
Thanks for the information Petar, but I do not see how the links you sent help me with the issue.
I already know how to create a Template Class that implements ITemplate and apply this template on create to the Template DataField (and its header). The links reference how to make one of Item Templates and how to apply it to a TemplateDataField that you are creating. I am doing this already (this is what is in the example).
The problem is that on postback the header image disappears. Since the code to re-create the grid column structure does not need to run, I do not re-create the TemplateDataField so the code to "set" the header template does not run again. I running an update on the TemplateDataField in the Row Init of the grid. The row images show up just fine, but the Header images do not. The only way to set it that I can see is to run the same code I used to in the InstatiateIn of the Header Template which is not ideal as I would then have the same code in two places.
I noticed that the Header has a TemplateId, but I am not sure how to set the TemplateId
How do I programmatically add a template to the grid so that I can reference it later using the Template Id? I tried to add the Header Template I created to the WebDataGrid's Template object, but there seem to be no way to set a Template's TemplateId when you add it unless I am missing something.
If there was something about this on the links you sent, please let me know, I did not see anything for this.
Thank you for your reply.
I am attaching a sample illustrating how a template may be added to the template collection programmatically. Note that the template itself needs to be reinstintiated on every postback. As for the header template of a templated column, its template control should be instantiated separately, for instace:
Please let me know if you have any questions.
Thanks for the SS of Code. That was very helpful.
I am guessing that WebDataGrid1_Init happens prior to Page_Load. Given that our columns are created dynamically and not preset, where would you suggest that I set the HeaderTemplate in order to get that to work?
Please do not hesitate to contact me if you have any further questions.
In this case you may try moving your column addition and template instantiation code in the Page_Load stage. For instance, with respect to the above sample:
Please feel free to contact me if you have any questions.