Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Datagrid Control (http://www.velocityreviews.com/forums/f60-asp-net-datagrid-control.html)
-   -   detect remaining rows in a PageIndexChanged event (http://www.velocityreviews.com/forums/t759492-detect-remaining-rows-in-a-pageindexchanged-event.html)

Marc Miller 09-11-2003 08:02 PM

detect remaining rows in a PageIndexChanged event
 
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.DataGridPageChangedEvent Args) 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



Lewis Wang [MSFT] 09-12-2003 07:00 AM

RE: detect remaining rows in a PageIndexChanged event
 
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" <mmiller@epix.net>
| From: "Marc Miller" <mmiller@epix.net>
| 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#JeDHA.1732@TK2MSFTNGP12.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
| NNTP-Posting-Host: inet1.ct-enterprises.com 209.74.63.71
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.aspnet.datagridc ontrol:6591
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
|
| 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.DataGridPageChangedEvent Args) 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
|
|
|


Marc Miller 09-12-2003 02:43 PM

Re: detect remaining rows in a PageIndexChanged event
 
Thank you Lewis....It works perfectly!

Marc


"Lewis Wang [MSFT]" <v-lwang@online.microsoft.com> wrote in message
news:rf4ARuPeDHA.1112@cpmsftngxa06.phx.gbl...
> 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" <mmiller@epix.net>
> | From: "Marc Miller" <mmiller@epix.net>
> | 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#JeDHA.1732@TK2MSFTNGP12.phx.gbl>
> | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
> | NNTP-Posting-Host: inet1.ct-enterprises.com 209.74.63.71
> | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.phx.gbl
> | Xref: cpmsftngxa06.phx.gbl
> microsoft.public.dotnet.framework.aspnet.datagridc ontrol:6591
> | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
> |
> | 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.DataGridPageChangedEvent Args) 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
> |
> |
> |
>





All times are GMT. The time now is 06:26 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.