Solved

Getting reference to Datagrid Footer controls

Posted on 2004-04-04
3
354 Views
Last Modified: 2008-03-10
I am using the footer as my Add Item row. I need to get a reference to a dropdownlist control and set a selected item. I need to do this anytime the page is rebound. DataGrid.Findcontrol("cboAddCBO")  returns Nothing. It seems there is no EditItem index associated with the footer either. The only time I can get a reference to the footer item is when I click a button in the footer row (using the ItemCommand event). Surely there is a way to get a reference to the footer row another way......
0
Comment
Question by:Misledman
3 Comments
 
LVL 12

Accepted Solution

by:
dfiala13 earned 250 total points
ID: 10752383
Yes, you can.  There are two ways...

When you bind the grid, you can access ithe footer item in the ItemDataBound event handler...


    Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound

        If (e.Item.ItemType = ListItemType.Footer) Then
            Dim ddl As DropDownList
            ddl = New DropDownList
            ddl.ID = "cboAddCBO"
            e.Item.Cells(0).Controls.Add(ddl)
        End If
    End Sub

On a postback you need to be a little trickier because as you found out the FooterItem is not part of the Items collection.

So you need to look in the collection of controls for the grid.  The grid itself only has one control which is the DataGRidTable.  This control actually holds all the Items (rows) including the footer and header.  The footer Item is always the last control in the Table so you can get it like so.  Then you need to look in the cell you created the dropdownlist in to get a reference to it...

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim dgiFooter As DataGridItem
        Dim ddl As DropDownList
        With DataGrid1.Controls(0)
            dgiFooter = .Controls(.Controls.Count - 1)
            ddl = dgiFooter.Cells(0).FindControl("cboAddCBO")
        End With

    End Sub
0
 
LVL 1

Author Comment

by:Misledman
ID: 11079299
Sorry.... I thought I had cleaned up all my questions....
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question