Accessing Controls in the Footer Template of a DataGrid

[NOTE:  This was originally posted at DevAuthority.com on 7/19/2005.]

I was recently tasked with applying some logic to an existing page where a datagrid was used to add and edit data.  This is nothing uncommon mind you, but I have (believe it or not) never used controls in the footer template.  The task involved determining whether specific controls were visible or not at runtime.  Since the footer template does not belong to the items collection I would be unable to see this using the EditItemIndex property.  After jumping through hoops I found that the way to gain access to a control in the footer.  In the following example I’m looking for a LinkButton, but the process could easily be used to find any control: I just thought others may be able to benefit from this basic principle that I seemed to struggle with.

Dim footerIndex As Integer = Me.MyDataGrid.Controls(0).Controls.Count - 1
Dim myButton As LinkButton
myButton =
CType(Me.MyDataGrid.Controls(0).Controls(footerIndex).FindControl("cmdThisButtonsID"), LinkButton)

 

Print | posted @ Friday, November 09, 2007 5:18 AM

Comments on this entry:

Gravatar # re: Accessing Controls in the Footer Template of a DataGrid
by JD at 1/17/2008 3:20 PM

I tried the above code and it did not work for me. Still couldn't access the text box that is in the footer.

Comments have been closed on this topic.