?
Solved

GridView RowCommand Pagechanged

Posted on 2007-11-28
5
Medium Priority
?
2,187 Views
Last Modified: 2013-11-07
I have a griidview control.  When the user changes the selected row on the gridview I change a formview to display the information as well (allowing the user to edit the row via a formview).  I do this in the rowcommand event of the gridview.  Linking the formview to the gridview row by e.CommandArgument in the rowcommand event.  I needed to do it like this so it picked up the newly changed row.  

Now when I have my gridview do paging, it has the commandargument as the rowvalue of the dataset as opposed to the rowvalue of the displayed grid.  so then it fails when i try to get the row from the grid.

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

For example: For a test I set the rows per page to be 2.  My total rows are 3.  So when i am on page 1 no problem at all.  When I go to page 2 I get an error.  When i print out the value of index it is 2.  

It then throws an error since there is only 1 row on that gridview page, when I try to Dim Row above.

Any ideas here?
0
Comment
Question by:Fraser_Admin
[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
  • 4
5 Comments
 
LVL 11

Accepted Solution

by:
cmhunty earned 1500 total points
ID: 20365543
Not a very tidy way but would think it would work - can you not use this?


Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim currentIndex As Integer = index - (gvSample.PageIndex * intItemsPerPage)
Dim row As GridViewRow = gvSample.Rows(current)

Open in new window

0
 

Author Comment

by:Fraser_Admin
ID: 20367438
there is no build in functionality which allows you to get the current row on the current page?
0
 

Author Comment

by:Fraser_Admin
ID: 20367507
in the rowcommand event it uses the old value.  so if page 1 is display and then i click on page 2 it is firing the rowcommand event and the pageindex = 0, when really it should be 1.  so i guess that won't work.

is there anyways to have in there if the rowcommand event is fired due to a page break then skip it or something?
0
 

Author Comment

by:Fraser_Admin
ID: 20367510
oops i mean due to a page change not a page break.
0
 

Author Comment

by:Fraser_Admin
ID: 20403568
any ideas here?  
0

Featured Post

TCP/IP Network Protocol Cheat Sheet

TCP/IP is a set of network protocols which is best known for connecting the machines that make up the Internet. The truth is that TCP/IP is one of the oldest network protocols and its survival is mainly based on its simplicity and universality.

Question has a verified solution.

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

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

770 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