Solved

Getting reference to Datagrid Footer controls

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now