Problem when adding paging to gridview

Last post 04-13-2007 8:14 AM by JRICE. 4 replies.

Sort Posts:

  • Problem when adding paging to gridview

    04-13-2007, 3:24 AM
    • Loading...
    • pete_l
    • Joined on 11-21-2005, 11:46 AM
    • Posts 11

    Hi


    I have a gridview that is bound to an ObjectDataSource that displays a varying amount of rows depending on some parameters passed to the Objectdatasource.  On certain rows I am performing actions on the gridview_rowdatabound event - things like changing the tooltip for a cell depending on data etc.  In this code I grab some of the cells returned to the gridview, but not displayed, so that I can use the data to add to the information displayed.

    example
    -------
       Protected Sub gvObj_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvObj.RowDataBound

            Dim rowPic As String = DataBinder.Eval(e.Row.DataItem, "cat_picture_available")
            Dim rowTitle As String = DataBinder.Eval(e.Row.DataItem, "cat_title")
            Dim rowDesc As String = DataBinder.Eval(e.Row.DataItem, "cat_desc")
            Dim rowCatId As String = DataBinder.Eval(e.Row.DataItem, "cat_id")
            Dim rowText As String = e.Row.Cells.Item(1).Text

            If rowPic = "Y" Then
                e.Row.Cells.Item(0).ToolTip = rowTitle
                e.Row.Cells.Item(1).Text = "<a href=""pgDetails.aspx?ID=" & rowCatId & """>" & row1text & "</a>"
            Else
                e.Row.Cells.Item(0).Text = ""
            End If

    This works fine until I decided to turn paging on in the gridview control and I get an error on the line:

            Dim rowText As String = e.Row.Cells.Item(1).Text

    Error displayed is

    Specified argument was out of the range of valid values.
    Parameter name: index
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
    Parameter name: index


    If I turn paging back off it works correctly again.


    Can anyone help with this problem?

    Thanks

  • Re: Problem when adding paging to gridview

    04-13-2007, 7:24 AM
    • Loading...
    • pete_l
    • Joined on 11-21-2005, 11:46 AM
    • Posts 11

    Hi all

     I found a work around the problem - I've added a conditional check so that the line of code that was causing the error only gets call for datarows.

     If e.Row.RowType = DataControlRowType.DataRow Then

         row1text = e.Row.Cells.Item(1).Text

     

    End If

     I'm not exactly sure why this works but it appears to.

    Pete

     

  • Re: Problem when adding paging to gridview

    04-13-2007, 7:44 AM
    Answer
    • Loading...
    • JRICE
    • Joined on 05-10-2006, 8:52 PM
    • Lebanon-Beirut
    • Posts 667

    The error appeared when

     e.Row.RowType = DataControlRowType.Pager

    it couldnt then find e.Row.Cells.Item(1).Text

     

    HTH

    Please remember to "Mark As Answer" if this post answered your question!

    Bilal Shouman - MCAD.NET

    |My Blog|
    ---------------------------------


  • Re: Problem when adding paging to gridview

    04-13-2007, 7:57 AM
    • Loading...
    • pete_l
    • Joined on 11-21-2005, 11:46 AM
    • Posts 11

    I thought that it would be something like that, although I thought the same problem would have occurred when the rowtype was 'Header'. I didn't realise that pager had it's own rowtype.

     

    Thanks

  • Re: Problem when adding paging to gridview

    04-13-2007, 8:14 AM
    • Loading...
    • JRICE
    • Joined on 05-10-2006, 8:52 PM
    • Lebanon-Beirut
    • Posts 667

    Glad to know that everything is ok :)

     

    Please remember to "Mark As Answer" if this post answered your question!

    Bilal Shouman - MCAD.NET

    |My Blog|
    ---------------------------------


Page 1 of 1 (5 items)
Microsoft Communities
Page view counter