?
Solved

Getting reference to Datagrid Footer controls

Posted on 2004-04-04
3
Medium Priority
?
357 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 1000 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

752 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