Hi All,
I (may) have a problem with an application containing a radgrid.
Because I do not know the number of columns at designtime, I declared the radgrid in the aspx file without columns, and build the grid structure in the code behind (In the NeedDataSource() event after data is fetched from the database).
In order to create 3 footerrows, my plan was to create a footertemplate, but I have read that this must be done in the page_init event.
During page_init however, I do not know the number of columns to create .... so I was stuck here.
I may have found a solution that works (Inspired from another thread about 2 HeaderRows).
During Grid.PreRender i add additional footerrows. It seems to work ok, but I am not sure if this is reliable.
Any comments ?
Thanks.
Here is the code:
I (may) have a problem with an application containing a radgrid.
Because I do not know the number of columns at designtime, I declared the radgrid in the aspx file without columns, and build the grid structure in the code behind (In the NeedDataSource() event after data is fetched from the database).
In order to create 3 footerrows, my plan was to create a footertemplate, but I have read that this must be done in the page_init event.
During page_init however, I do not know the number of columns to create .... so I was stuck here.
I may have found a solution that works (Inspired from another thread about 2 HeaderRows).
During Grid.PreRender i add additional footerrows. It seems to work ok, but I am not sure if this is reliable.
Any comments ?
Thanks.
Here is the code:
Protected
Sub
Grid_TimeSheet_PreRender(
ByVal
sender
As
Object
,
ByVal
e
As
System.EventArgs)
Handles
Grid_TimeSheet.PreRender
AddFooterRow(1)
AddFooterRow(2)
End
Sub
Protected
Sub
AddFooterRow(
ByVal
marker
As
Integer
)
' get the current footer
Dim
footer
As
GridItem() = Grid_TimeSheet.MasterTableView.GetItems(GridItemType.Footer)
' get the current TFoot element
Dim
foot
As
GridTFoot =
CType
(footer(0).Parent.Controls(0).Parent, GridTFoot)
Dim
LastFooterPos
As
Integer
= 0
For
n = 0
To
foot.Controls.Count - 1
If
TypeOf
(foot.Controls(n))
Is
GridFooterItem
Then
LastFooterPos = n
End
If
Next
Dim
newFooterItem
As
GridFooterItem =
New
GridFooterItem(Grid_TimeSheet.MasterTableView, 0, 0)
PopulateNewFooterItem(newFooterItem, foot.Controls(LastFooterPos), marker)
foot.Controls.AddAt(LastFooterPos + 1, newFooterItem)
End
Sub
Protected
Sub
PopulateNewFooterItem(
ByVal
footer
As
GridFooterItem,
ByVal
existingfooter
As
GridFooterItem,
ByVal
marker
As
Integer
)
For
Each
fc
In
existingfooter.Cells
Dim
new_fc
As
TableCell =
New
TableCell
new_fc.Text = marker.ToString()
footer.Cells.Add(new_fc)
Next
End
Sub