Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

.net Gridview Paging issue with Row Command

Posted on 2010-11-18
2
Medium Priority
?
1,134 Views
Last Modified: 2012-05-10
I have a gridview that allows paging and uses a row command event.

The gridview column that caused the issue is:
                        <asp:TemplateField>
                            <ItemTemplate>
                                <asp:LinkButton ID="LinkButton1" Runat="server" OnClientClick="return confirm('Are you sure you want to delete this item?');"
                                CommandName="ConvertDelete" CommandArgument="<%# Container.DataItemIndex %>">Delete</asp:LinkButton>
                            </ItemTemplate>
                            <ItemStyle BackColor="#FFC0C0" Font-Size="X-Small" />
                        </asp:TemplateField>


The codebehind code that causes the issue is:

                Dim index As Integer = Convert.ToInt32(e.CommandArgument)
                Dim row As GridViewRow = gridview1.Rows(index)

The error reads:

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

The index value is greater than the page size.  Everything works on Page 1 but fails on all other pages.

Please help!
0
Comment
Question by:dtechfish
[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 Comments
 
LVL 13

Accepted Solution

by:
devlab2012 earned 2000 total points
ID: 34163983
Why you are setting CommandArgument to Container.DataItemIndex. Set it directly to the primary key of your table like the ItemID which you can use to delete the record.
0
 
LVL 32

Expert Comment

by:Erick37
ID: 34164037
You  can set the CommandArgument of the LinkButton in the grid's RowCreated event.  

See the example here:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowcommand(VS.80).aspx
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

610 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