Solved

Auto generated gridview paging index out of range

Posted on 2007-12-06
3
1,778 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
  • 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Icons and Colors for Terms 3 24
Problem to error 4 43
Syntax error 9 45
I need help displaying images in a ListBox control in my WPF application with VB.Net code-behind. 1 20
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

914 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now