Avatar of GlobaLevel
GlobaLevelFlag for United States of America

asked on 

asp.net - issue with onrowdataboun=".." causes only only 1 row to pull when there are many rows to pull

Whne I add this to the gridview...
onrowdatabound="GridView1_RowDataBound"

it only pulls 1 row..

when I delete it form the gridview..it pulls all rows...rather odd...
Protected Sub GridView1_RowDataBound(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
   
        Try
            If e.Row.RowType = DataControlRowType.DataRow Then
                Dim itemId As String = Me.GridView1.DataKeys(i).Value
                Dim hf As HiddenField = CType(e.Row.FindControl("HF_itemId"), HiddenField)
                hf.Value = itemId
                Session("Game_id" & i) = hf.Value
                i = i + 1
                             
      
            End If
        
        Catch ex As Exception
            Throw ex
        End Try
        End Sub



' ====


  <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Game_Id"
        CellPadding="4" ForeColor="#333333" onrowdatabound="GridView1_RowDataBound" onrowupdated="chkD2Status_CheckedChanged"      
        AllowPaging="True" AllowSorting="True" Height="200px" Width="900px" 
        Font-Size="Small" style="margin-right: 57px">
            <RowStyle BackColor="#EFF3FB" />
            <Columns>
                <asp:BoundField DataField="Game_Time" HeaderText="Game Time" ReadOnly="True" 
                    SortExpression="Game_Time" />
                <asp:TemplateField HeaderText="Away Team/Home Team">
                    <ItemTemplate>
                        <asp:Label ID="Label5" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"home_team") %>' CssClass="MakePicks_col_2_sec_1" ></asp:Label>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
                        <asp:Label ID="Label6" runat="server" Text="@" Font-Bold="True" CssClass="MakePicks_col_2_sec_2" ></asp:Label>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b>
                        <asp:Label ID="Label7" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"away_team") %>' CssClass="MakePicks_col_2_sec_3" ></asp:Label>
                        </b>
                        <br />
                        <b>
                        <asp:CheckBox ID="CheckBox1" runat="server"  Text='<%#DataBinder.Eval(Container.DataItem,"home_team_spread") %>' CssClass="MakePicks_col_2_sec_1"></asp:CheckBox>
                      
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <asp:CheckBox ID="CheckBox2" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"away_team_spread") %>' CssClass="MakePicks_col_2_sec_3"></asp:CheckBox>
               
                        <br />

Open in new window

ASP.NET.NET ProgrammingVisual Basic.NET

Avatar of undefined
Last Comment
GlobaLevel
ASKER CERTIFIED SOLUTION
Avatar of gery128
gery128
Flag of India image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of cubaman_24
cubaman_24
Flag of Spain image

Hello:
Why you catch the exception to just rethrow it? This is a bad practice.
What about loggin the exception? At least, use Debug.Write(ex)

Avatar of GlobaLevel
GlobaLevel
Flag of United States of America image

ASKER

What you see when you debug? Put breakpoint on rowdatabound method and see if it loops thru all the datatable rows or what happens exactly.
>>>It is looping thru the onRowDataBound event...but it throws an error:

Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo