Footer not in datagrid items list

M

Matt

I see many posts on this topic but still can't find a solution that
works. I'm trying to access a dropdownlist in my datagrid footer when
another dropdownlist in the footer is accessed. The most logical
advice I've seen is to loop thru the controls like this:

Dim myDGItem As DataGridItem
Dim myTextBox As TextBox
For Each myDGItem In DataGrid1.Items
If myDGItem.ItemType = ListItemType.Footer Then
For Each myTextBox In myDGItem.Cells(index).Controls
...
Next
End If
Next

This doesn't work though because it appears the footer isn't part of
the items list. All I get is a type of "item" and "alternating item".

I know the controls exist because I have a subroutine operating on the
selectedindexchange for the dropdownlists. The problem is that when
you capture this event you get a System.EventArgs instead of
DataGridItemEventArgs. Again, I think the problem is that a footer
isn't part of the items list of a datagrid. Here's the prototype for
the subroutine that captures the index change:

Protected Sub ddl_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs)

It's from this sub that I want to access the other dropdownlist in the
footer of the datagrid.
 
S

Scott Mitchell [MVP]

Matt, unfortunately the DataGrid's Items property contains only those rows
that undergo databinding, namely the Items and AlternatingItems. From the
documentation:

"Note Only items bound to the data source are contained in the Items
collection. The header, footer, and separator are not included in the
collection."
ms-help://MS.NETFrameworkSDKv1.1/cpref/html/frlrfsystemwebuiwebcontrolsdat
agridclassitemstopic.htm


To access the footer you need to use the DataGrid's ItemCreated event,
creating an event handler. To see an example of this in action, check
out. You can also access the Footer in the ItemCommand event, assuming
the Button causing the Command event is located in the footer. Hopes this
helps shed some light on the matter...


--

Scott Mitchell
(e-mail address removed)
http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com

* When you think ASP, think 4GuysFromRolla.com!
 
M

Matt

Scott,

Thanks for the reply. Slowly I'm getting an understanding of this issue.
I have a few comments as follow up.

First, I think you left a link out of your message because you just say
"check out..." then continue with the sentence.

Second, the main problem that I'm (and others) are facing is when a
dropdownlist is in the footer. In my case I want to access the footer
when the index changes on my dropdownlist. All my dropdownlist objects
in my footer share a common
OnSelectedIndexChanged="ddl_SelectedIndexChange" command. The signature
for this type of event is an object (the sender) and a System.EventArgs
instance.

This is the problem. I don't have access to the DataGrid's Event
Handler, I have the System.EventArgs instead. My knowledge isn't
extensive enough to figure out how that can be altered, if it even can.

What I can't understand is why we are not allowed to access the footer
if I have the DataGrid object? I can refer to the DataGrid in my custom
IndexChange function but, as mentioned before, there isn't a way to
access the footer. You can access the "items" in the grid but not the
footer. This seems to be a very strange behavior since the footer is
part of the DataGrid. Again, there must be reason for why the ability
to access was left out but it's beyond me.

The only solution I can up with was to create a recursive function to
search through all the controls in a control by ID until you find the
matching ID. Using this method I can find the dropdownlist in my footer
which is in my DataGrid, but I have to loop through all the other
controls in the DataGrid first. This seems very waseful to me.

I would be very glad to have someone suggest another solution.
 
C

Colin Young

Because that would be sensible :)

I think part of the problem (and I'm only guessing here because I'm not
privy to the secrets of the DataGrid code) is that the footer is really a
"footer." A footer would be attached to the tabular data but distinct from
it. Instead, MS has elected to treat the footer as a signal that it should
have some special formatting applied to it.

I'm sorry that I don't have an answer to your question (I'm not entirely
sure I understand it because a virus has left me feeling a little light
headed, and I'm not entirely certain that I would be able to answer it in a
coherent manner today), but hopefully you now have a deeper understanding of
the abomination that is the DataGrid.

Colin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top