iSeller Commerce
iSeller POS Retail
iSeller POS F&B
iSeller POS Express
Crosslight
WebUI
ClientUI
What's New
Download Trial
Web Solution
Mobile Solution
Enterprise Solution
Custom Development
Blog
Community
Latest Development Blogs
ForumPostTopic
Browse By Tag
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:
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
Hi Brad,
Yes, to add controls to a cell, we can only use a template column. In here, I attached you a simple sample on how to create a cell Template in code behind. Kindly take a look and see it might can help you.
In my opinion, it will be a better method to inherits a cell template from ITemplate and implements the instantiateIn method.
Thank you and have a nice day.
Best Regards,
Andi Santoso
Thanks Andi, but in my case, I cannot just create a checkbox or a label in my template because I am adding controls dynamically. Sometimes I'm creating labels, sometimes checkboxes, sometimes maybe a combination of several controls will need to be added and it would be very time consuming to create a template for each of these scenarios. It seems that the blank template works ok though. I appreciate your help.
Yes, that might work. However, perhaps, we can pass a value to the template class and create a validation depends on the paramater's value. Please kindly take a look at my new sample of template column. See if it might help you.
Hi Andi,
Unless I'm just misunderstanding how this is used, I don't think that this will solve my problem either. What I need is to dynamically add various controls to a cell during the InitializeRow event but I won't know what all will be put in there. Here is an example:
If Not e.Row.Cells.GetNamedItem("FirstName") Is Nothing Then Dim lbl As New Label("I want to add a label in this case") Dim lt As New Literal("Maybe I also want to add a literal") Dim ddl As New DropDownList() ddl.Items.Add(New ListItem("I also want a dropdownlist")) e.Row.Cells.GetNamedItem("Test").GetTemplateContainer().Controls.Add(lbl) e.Row.Cells.GetNamedItem("Test").GetTemplateContainer().Controls.Add(lt) e.Row.Cells.GetNamedItem("Test").GetTemplateContainer().Controls.Add(ddl) End If
That is the sort of thing that I need to do. I want to add various server controls to a cell at run time but I don't know what sort of template can accomodate that. I wonder if perhaps I'm using the incorrect column type? Is there a way to accomplish what I am trying to do?
Hello Brad,
Please let me try to ensure your scenario once again.
e.g, You have 3 rows in WebGrid and one TemplateColumn.
In a cell which used template column, you want to add dynamic control in there.such as:at row 1, you want the cell to be having "label"at row 2, you want the cell to be having "literal"at row 3, you want the cell to be having "dropdown"
Is this what you are looking for? So at each row, the control at template column can be different depends on the condition (dynamic).
Unfortunately, you could not do this scenario. Please let me know if I wrongly in understanding your scenario.
Regards,Handy
Handy,
That is close to what we need to do. Basically, based on various conditions related to access rights, roles, etc., we want a certain column to contain one control like, for instance, a dropdownlist or a checkbox, and, in other conditions, we want the column to just contain a label. This is a very common scenario and I would be surprised if this is not possible with the WebGrid. Is this sort of thing available via some other type of column? Perhaps template column is not the right column type? How do you recommend that we accomplish this task?
Unfortunately, at this moment, our WebGrid does not support that kind of feature. WebGrid will only allow to have one type of template column for one particular column only. Just as my colleague explained, we cannot have a different type of column template type for each different row.
or
Choose this if you're already a member of Intersoft Community Forum. You can link your OpenID account to your existing Intersoft Social ID.
Choose this if you don't have an Intersoft account yet. Your authenticated OpenID will be automatically linked to your new Intersoft account.
Enter your Wordpress Blogname