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
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