473,396 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Looping Through Controls In DataGrid

Hello, I am trying to figure out how to get to the "footer" control in a
datagrid. I set up the following logic:

Dim cntrl As Control
Dim cnt As Integer = dgNewMovies.Controls.Count

For Each cntrl In dgNewMovies.Controls
Dim cntrlName As String = cntrl.ID
If TypeOf cntrl Is System.Web.UI.WebControls.DataGridItem Then
Dim item As System.Web.UI.WebControls.DataGridItem = CType(cntrl,
System.Web.UI.WebControls.DataGridItem)
If item.ItemType = ListItemType.Footer Then

End If
End If
Next
I only get a single control... My count (2nd instruction) only has a count
of 1.

I thought that perhaps I needed to look for System.Web.UI.Control but the
way that it is stated is a System.Web.UI.Control.

So how do I iterate through all of the controls on the Datagrid!

Thanks in advance for your assistance!!!
Nov 18 '05 #1
2 1488
Hi Jim,

The easiest way is to test for the footer in the ItemCreated event. Here's
some code:

<asp:DataGrid id="DataGrid1" runat="server"
ShowFooter="True"></asp:DataGrid>

----
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
If Not IsPostBack Then
DataGrid1.DataSource = CreateDataSource()
DataGrid1.DataBind()
End If
End Sub

Private Sub DataGrid1_ItemCreated _
(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) _
Handles DataGrid1.ItemCreated
If e.Item.ItemType = ListItemType.Footer Then
e.Item.Cells(0).Text = Date.Now.ToLongDateString
End If
End Sub

Function CreateDataSource() As ICollection
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn("CurrencyValue", GetType(Double)))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dt.Rows.Add(dr)
Next i
Dim dv As New DataView(dt)
Return dv
End Function 'CreateDataSource

"Jim Heavey" <Ji*******@nospam.com> wrote in message
news:Xn*********************************@207.46.24 8.16...
Hello, I am trying to figure out how to get to the "footer" control in a
datagrid. I set up the following logic:

Dim cntrl As Control
Dim cnt As Integer = dgNewMovies.Controls.Count

For Each cntrl In dgNewMovies.Controls
Dim cntrlName As String = cntrl.ID
If TypeOf cntrl Is System.Web.UI.WebControls.DataGridItem Then
Dim item As System.Web.UI.WebControls.DataGridItem = CType(cntrl,
System.Web.UI.WebControls.DataGridItem)
If item.ItemType = ListItemType.Footer Then

End If
End If
Next
I only get a single control... My count (2nd instruction) only has a count
of 1.

I thought that perhaps I needed to look for System.Web.UI.Control but the
way that it is stated is a System.Web.UI.Control.

So how do I iterate through all of the controls on the Datagrid!

Thanks in advance for your assistance!!!

Nov 18 '05 #2
I ma trying to write a CustomValidator server edit, so I do not think the
ItemCreated Event will help...will it?
Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Diva | last post by:
Hi, I have a data grid in my application. It has 20 rows and I have set the page size as 5. I have a Submit button on my form and when I click on Submit, I need to loop through the rows in the...
4
by: Peter | last post by:
I have an ASP.NET form written in C#, on this form I have few controls and a DataGrid control, under the DataGrid control I have few more controls. The DataGrid defaults to display 10 items. When...
1
by: bill yeager | last post by:
I did some more debugging and found the following: 1) I placed the following code in the button event just to see if I could cycle thru the datagrid control collection: <code> Dim strhello As...
12
by: Daniel Walzenbach | last post by:
Hi, I want to display a Label in a DataGrid according to some condition. I therefore check whether the condition is true in the ItemDateBound EventHandler of the DataGrid. Unfortunately the...
2
by: Jim Bancroft | last post by:
This may be a no-brainer, but I'm sure I follow what's happening here... I have a DataGrid with one DropDownList per row. If I select a few DropDown items and postback my page, I can't loop...
0
by: | last post by:
Greets All, Question on data in datagrid /listbox and looping? I’m trying to decide the best way to write this code. 1 would like the user to make several selections from one listbox/combo box...
0
by: | last post by:
Greets All, Question on data in datagrid /listbox and looping? I’m trying to decide the best way to write this code. 1 would like the user to make several selections from one listbox/combo box...
15
by: Arpan | last post by:
Consider the following code which retrieves data from a SQL Server 2005 DB table & displays it in a DataGrid: <script runat="server"> Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)...
0
by: rn5a | last post by:
Suppose I have the following DataGrid: <asp:DataGrid ID="dgUsers" OnUpdateCommand="UpdateDG" runat="server"> <Columns> <TemplateColumn HeaderText="NAME"> <ItemTemplate> <asp:Label...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.