CellTemplate

7 replies. Last post: June 1, 2010 2:10 PM by Andi Santoso
Tags :
  • (None)
  • New Discussion
  • New Question
  • New Product Feedback
Brad LoveallMember

I've got a question about the Template column. I have a scenario where I want to add controls to a cell at run time during the InitializeRow event. From what I understand, though, the WebGrid does not allow one to add controls to a cell unless it is a Template column. First, I would like to know whether I'm right about that. Second, if it is true that I must use a Template column, then I have another problem, which is that i do not want to define my template at design time so I've been doing this:

<ISWebGrid:WebGridColumn Name="Test" DataMember="Test" Caption="Test" ColumnType="Template"><CellTemplate></CellTemplate>
</ISWebGrid:WebGridColumn>

Then, in the InitializeRow event, I can get access to e.Row.Cells.GetNamedItem("Test").GetTemplateContainer() and can add controls.

This works fine as far as it goes but in many cases, I have to build columns dynamically at run time and add CellTemplates to it and in still other cases, I know that I want to add controls to my cell but I won't know until run time which controls to add, and so creating a celltemplate won't work. But all of the examples that I have seen require the creation of a class that inherits from ITemplate and then implements the InstantiateIn method. In my case, if I don't want to predefine a template, is the best approach just to create a class which implements ITemplate but which then does nothing? Is there a better option?

Thanks,

Brad

All times are GMT -5. The time now is 10:21 PM.
Previous Next