Solved

GridView RowCommand Pagechanged

Posted on 2007-11-28
5
2,183 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
  • 4
5 Comments
 
LVL 11

Accepted Solution

by:
cmhunty earned 500 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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

828 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