Solved

Getting reference to Datagrid Footer controls

Posted on 2004-04-04
3
355 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

730 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