Solved

Auto generated gridview paging index out of range

Posted on 2007-12-06
3
1,782 Views
Last Modified: 2013-11-26
I have an auto generated gridview that requires paging (and it must be auto generated since my original sql is dynamic). I need to hide a column, which is successfully done, but when I include AllowPaging="True" in the gridview, I receive the error:

Specified argument was out of the range of valid values. Parameter name: index

I know it's because the gridview is reading the first page returned and can't the second page, but how do I go about fixing this? The snippit was done with Northwind.

Thanks
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
		<br />
		<asp:GridView ID="GridView1" OnRowDataBound="GridView1_RowDataBound" runat="server" 
		DataSourceID="SqlDataSource1" AllowPaging="True">
		</asp:GridView>
		
		<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
			SelectCommand="SELECT [ProductID], [ProductName] FROM [Alphabetical list of products] ORDER BY [ProductName]">
		</asp:SqlDataSource>
    
    </div>
    </form>
</body>
</html>
 
 
AND
 
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
		e.Row.Cells(1).Visible = False
End Sub

Open in new window

0
Comment
Question by:barnesco
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 12

Expert Comment

by:madhevan_pillai
ID: 20425569
Try this

    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
       
        If e.Row.RowType = DataControlRowType.DataRow Or e.Row.RowType = DataControlRowType.Header Then

            e.Row.Cells(1).Visible = False
        End If

    End Sub
0
 
LVL 12

Accepted Solution

by:
madhevan_pillai earned 500 total points
ID: 20425570
Hi try this
    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
       
        If e.Row.RowType = DataControlRowType.DataRow Or e.Row.RowType = DataControlRowType.Header Then
 
            e.Row.Cells(1).Visible = False
        End If
 
    End Sub

Open in new window

0
 

Author Closing Comment

by:barnesco
ID: 31413312
Works beautifully. Thank you!
0

Featured Post

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question