detect remaining rows in a PageIndexChanged event

Discussion in 'ASP .Net Datagrid Control' started by Marc Miller, Sep 11, 2003.

  1. Marc Miller

    Marc Miller Guest

    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
    Marc Miller, Sep 11, 2003
    #1
    1. Advertising

  2. 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" <>
    | From: "Marc Miller" <>
    | 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#>
    | 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
    |
    |
    |
    Lewis Wang [MSFT], Sep 12, 2003
    #2
    1. Advertising

  3. Marc Miller

    Marc Miller Guest

    Thank you Lewis....It works perfectly!

    Marc


    "Lewis Wang [MSFT]" <> wrote in message
    news:...
    > 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" <>
    > | From: "Marc Miller" <>
    > | 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#>
    > | 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
    > |
    > |
    > |
    >
    Marc Miller, Sep 12, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TWlrZUc=?=
    Replies:
    0
    Views:
    487
    =?Utf-8?B?TWlrZUc=?=
    Jun 18, 2004
  2. JenHu
    Replies:
    0
    Views:
    539
    JenHu
    Oct 28, 2004
  3. bruceb
    Replies:
    0
    Views:
    1,197
    bruceb
    Jan 25, 2005
  4. Gopalan
    Replies:
    2
    Views:
    8,947
    =?Utf-8?B?YWx2aW56X2M=?=
    Jun 18, 2005
  5. abn
    Replies:
    0
    Views:
    628
Loading...

Share This Page