Hi There,
I have a Grid control with a column which is used to render an icon based on a bound value.
The DocumentIconTemplate class looks like this
and the custom column looks like this
All is well and this renders fine until I create a hierarchical grid or use some operation that requires a postback. When I expand the row (to show the second level of the hierarchy) my custom image disappears although all "text" based fields remain.When you expand the row the grid posts back to the server and when it comes back Grid columns that have Text set on them still have their values. I'm not sure if it the viewstate or the control heirarchy that is the problem here. On postback the grid doesn't call the InstantiateIn again so I presume it's trying to re-render itself just using viewstate.
It does keep the image if you use the <ItemTemplate> and create the image declaratively however outside of this simple test app the columns need to be created dynamically.
Any help/thoughts appreciated.
Adrian
I have a Grid control with a column which is used to render an icon based on a bound value.
The DocumentIconTemplate class looks like this
| Public Class DocumentIconTemplate |
| Implements ITemplate |
| Private m_Name As String |
| Public Sub New(ByVal name As String) |
| m_Name = name |
| End Sub |
| Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn |
| Dim dataCell As GridTableCell = container |
| Dim dataItem As GridDataItem = CType(container.NamingContainer, GridDataItem) |
| Dim img As New Image() |
| img.ID = m_Name |
| AddHandler img.DataBinding, AddressOf BindImage |
| container.Controls.Add(img) |
| End Sub |
| Public Sub BindImage(ByVal sender As Object, ByVal e As EventArgs) |
| Dim img As Image = CType(sender, Image) |
| Dim container As GridDataItem = CType(img.NamingContainer, GridDataItem) |
| img.ID = m_Name |
| img.ImageUrl = "Scr.Bmp" |
| End Sub |
| End Class |
and the custom column looks like this
| Dim column As GridTemplateColumn |
| column = New GridTemplateColumn() |
| column.HeaderText = "Type" |
| column.DataField = "Type" |
| column.UniqueName = "Type" |
| column.ItemTemplate = New DocumentIconTemplate("Type") |
| gridControl.MasterTableView.Columns.Add(column) |
All is well and this renders fine until I create a hierarchical grid or use some operation that requires a postback. When I expand the row (to show the second level of the hierarchy) my custom image disappears although all "text" based fields remain.When you expand the row the grid posts back to the server and when it comes back Grid columns that have Text set on them still have their values. I'm not sure if it the viewstate or the control heirarchy that is the problem here. On postback the grid doesn't call the InstantiateIn again so I presume it's trying to re-render itself just using viewstate.
It does keep the image if you use the <ItemTemplate> and create the image declaratively however outside of this simple test app the columns need to be created dynamically.
Any help/thoughts appreciated.
Adrian