detect remaining rows in a PageIndexChanged event

M

Marc Miller

When I bind the data to my datagrid I call a sub to change the backcolor of
the rows
based on a column value.

When the user changes pages in the grid, I again call the sub to change the
new rows backcolor.

The problem arises when there are less rows than PageSize property, i.e. if
PageSize is set to
10 and there are only 5 remaining rows of data I receive the error:
Index was out of range. Must be non-negative and less than the size of the
collection.
Parameter name: Index

I need somehow to know when to stop the call to the sub to change the row
colors.

Thanks for any help,
Marc


the code is :
Private Sub dgBPR_PageIndexChanged(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles
dgPODetails.PageIndexChanged

Me.dgPODetails.CurrentPageIndex = e.NewPageIndex

**** rebind the data here........******

Dim i As Integer

For i = 0 To nIsRecords - 1

' This is where I need to stop the call to rowcolor().

Me.rowcolor(i)

Next i

End Sub

----------------------------------------------------------------------------
-------------------------------------------------------------
Private Sub rowcolor(ByVal intRow As Integer)

If objDs.Tables(0).Rows(intRow).Item("closed_code") = "CLOSED" Then

Me.dgPODetails.Items(intRow).ForeColor = Color.FromName("Red")

Me.dgPODetails.Items(intRow).BackColor = Color.FromName("WhiteSmoke")

Else

Me.dgPODetails.Items(intRow).ForeColor = Color.FromName("DarkBlue")

Me.dgPODetails.Items(intRow).BackColor = Color.FromName("White")

End If

End Sub
 
L

Lewis Wang [MSFT]

Hi Marc,

You may use "DataGrid1.Items.Count" to get the number of the items in the
DataGrid on the current page. The indexes of the rows whose color will be
changed should not be greater than (DataGrid1.Items.Count -1 ).

Hope this helps.

Best regards,
Lewis
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
| Reply-To: "Marc Miller" <[email protected]>
| From: "Marc Miller" <[email protected]>
| Subject: detect remaining rows in a PageIndexChanged event
| Date: Thu, 11 Sep 2003 16:02:35 -0400
| Lines: 63
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
| Message-ID: <uTjwl#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| NNTP-Posting-Host: inet1.ct-enterprises.com 209.74.63.71
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.aspnet.datagridcontrol:6591
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
|
| When I bind the data to my datagrid I call a sub to change the backcolor
of
| the rows
| based on a column value.
|
| When the user changes pages in the grid, I again call the sub to change
the
| new rows backcolor.
|
| The problem arises when there are less rows than PageSize property, i.e.
if
| PageSize is set to
| 10 and there are only 5 remaining rows of data I receive the error:
| Index was out of range. Must be non-negative and less than the size of
the
| collection.
| Parameter name: Index
|
| I need somehow to know when to stop the call to the sub to change the row
| colors.
|
| Thanks for any help,
| Marc
|
|
| the code is :
| Private Sub dgBPR_PageIndexChanged(ByVal source As Object, ByVal e As
| System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles
| dgPODetails.PageIndexChanged
|
| Me.dgPODetails.CurrentPageIndex = e.NewPageIndex
|
| **** rebind the data here........******
|
| Dim i As Integer
|
| For i = 0 To nIsRecords - 1
|
| ' This is where I need to stop the call to rowcolor().
|
| Me.rowcolor(i)
|
| Next i
|
| End Sub
|
|
----------------------------------------------------------------------------
| -------------------------------------------------------------
| Private Sub rowcolor(ByVal intRow As Integer)
|
| If objDs.Tables(0).Rows(intRow).Item("closed_code") = "CLOSED" Then
|
| Me.dgPODetails.Items(intRow).ForeColor = Color.FromName("Red")
|
| Me.dgPODetails.Items(intRow).BackColor = Color.FromName("WhiteSmoke")
|
| Else
|
| Me.dgPODetails.Items(intRow).ForeColor = Color.FromName("DarkBlue")
|
| Me.dgPODetails.Items(intRow).BackColor = Color.FromName("White")
|
| End If
|
| End Sub
|
|
|
 
M

Marc Miller

Thank you Lewis....It works perfectly!

Marc


Lewis Wang said:
Hi Marc,

You may use "DataGrid1.Items.Count" to get the number of the items in the
DataGrid on the current page. The indexes of the rows whose color will be
changed should not be greater than (DataGrid1.Items.Count -1 ).

Hope this helps.

Best regards,
Lewis
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
| Reply-To: "Marc Miller" <[email protected]>
| From: "Marc Miller" <[email protected]>
| Subject: detect remaining rows in a PageIndexChanged event
| Date: Thu, 11 Sep 2003 16:02:35 -0400
| Lines: 63
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
| Message-ID: <uTjwl#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| NNTP-Posting-Host: inet1.ct-enterprises.com 209.74.63.71
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.aspnet.datagridcontrol:6591
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
|
| When I bind the data to my datagrid I call a sub to change the backcolor
of
| the rows
| based on a column value.
|
| When the user changes pages in the grid, I again call the sub to change
the
| new rows backcolor.
|
| The problem arises when there are less rows than PageSize property, i.e.
if
| PageSize is set to
| 10 and there are only 5 remaining rows of data I receive the error:
| Index was out of range. Must be non-negative and less than the size of
the
| collection.
| Parameter name: Index
|
| I need somehow to know when to stop the call to the sub to change the row
| colors.
|
| Thanks for any help,
| Marc
|
|
| the code is :
| Private Sub dgBPR_PageIndexChanged(ByVal source As Object, ByVal e As
| System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles
| dgPODetails.PageIndexChanged
|
| Me.dgPODetails.CurrentPageIndex = e.NewPageIndex
|
| **** rebind the data here........******
|
| Dim i As Integer
|
| For i = 0 To nIsRecords - 1
|
| ' This is where I need to stop the call to rowcolor().
|
| Me.rowcolor(i)
|
| Next i
|
| End Sub
|
|
-------------------------------------------------------------------------- --
| -------------------------------------------------------------
| Private Sub rowcolor(ByVal intRow As Integer)
|
| If objDs.Tables(0).Rows(intRow).Item("closed_code") = "CLOSED" Then
|
| Me.dgPODetails.Items(intRow).ForeColor = Color.FromName("Red")
|
| Me.dgPODetails.Items(intRow).BackColor = Color.FromName("WhiteSmoke")
|
| Else
|
| Me.dgPODetails.Items(intRow).ForeColor = Color.FromName("DarkBlue")
|
| Me.dgPODetails.Items(intRow).BackColor = Color.FromName("White")
|
| End If
|
| End Sub
|
|
|
 

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,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top