I want to place an image into the Grid Column's Header instead of Caption Text at run time. I have seen how to do this at design time (https://www.youtube.com/playlist?list=PLDAFFE8C757FED32E). I attempted to translate this into dynamically creating this at run time, but I am missing something. How do I do this for the WebDataGrid?
Here is what is created during design time:
<Templates> <ig:ItemTemplate ID="WebDataGrid1Template1" runat="server" TemplateID="Comments"> <Template> <img src="images/Notes.png" alt="Comments" /> </Template> </ig:ItemTemplate> </Templates>
I tried to create it like this but it does not work (no image shows up):
Dim commentsHeader As Infragistics.Web.UI.ItemTemplate = New Infragistics.Web.UI.ItemTemplate() commentsHeader.TemplateID = "Comments" Dim commentsImage As System.Web.UI.WebControls.Image = New System.Web.UI.WebControls.Image() commentsImage.ImageAlign = ImageAlign.Middle commentsImage.AlternateText = "Comments" commentsImage.ImageUrl = "images/Notes.png" commentsHeader.Controls.Add(commentsImage) WebDataGrid1.Templates.Add(commentsHeader)
Thanks for your help.
I think I am missing something here.
The link you provided seems to be refering to how to handle things for if I want images in the column's rows, not the column header. The header of a column does not have an ItemTemplate but asks for a TemplateID instead. If I do what they suggest and creating a class that implements ITemplate, then I do not have a TemplateID that I can use to apply to the column header's property. Since I cannot set the TemplateID I am not able to apply it to a column.
Hello greghendricks ,
The link from our documentation indeed doesn’t seem to explain in detail the setting needed for setting the header template.
The approach is similar though. Once you create the item template and set it’s TemplateId you still need to set a template that will contain you controls. For example:
commentsHeader.Template = new CustomItemTemplate();
And in the same way as explained for Item template create a class that implements ITemplate that contains the InstantiateIn method and in it create and add the controls you want to the container.
Also don’t forget to set the Header’s TemplateId to the newly created commentsHeader.TemplateID.
I’m attaching a sample for your reference. Let me know if you have any further questions or concerns regarding this.
Best Regards,
Maya Kirova
Developer Support Engineer
Infragistics, Inc.
http://ko.infragistics.com/support
That's it!
So create the template as I did above, but need to create a custom class implementing ITemplate like you would for a templatedatafield, and then set that Header.Template = custom class.
Thank you!
Hello greghendricks,
Let me know if you have any further questions regarding this.
That is what I thought and that is what I did. I am not sure what happened because yesterday it did not work (No image showed up). I did again today with the same exact code and now it works. Go figure.
Thanks again!
When using a TemplateDataField you have 3 templates you can apply to the field: HeaderTemplate, FooterTemplate and ItemTemplate. All are configured in the same way. An example for the ItemTemplate is explained in our documentation at:
http://help.infragistics.com/NetAdvantage/ASPNET/2011.1/CLR4.0/?page=WebDataGrid_Using_Item_Template.html
Basically you just need to access the Template field from the columns collection and from there set the HeaderTemplate property to the custom template.
Let me know if you need further assistance with this or if you have any questions or concerns.
Maya,
I tried this same code but using a TemplateDataField instead of a BoundField and the column's Header does not seem to use the TemplateID that is available to it. Any ideas why that is?
I'm glad this resolved your issue.Let me know if you need further assistance.