Solved

Getting reference to Datagrid Footer controls

Posted on 2004-04-04
3
353 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

831 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