Web app Datagrid - select button w/ paging not working

Hi,

     I have a datagrid set up with a Select Button Column.  This is a button that chooses the row and lets the code use that row's info in textbox/dropdownlist controls for the user to make changes.  The datagrid also has paging - 5 items per page.  When I run the program, everything seems fine.  Click the button on the first row, my label (triggered by the change) says 0, the 4th item makes the label say 3, etc.  The problem is when I click to the next page in the datagrid and click the first button, it still references 0.  The second button still references 1, etc etc.  What code do I need (I guess in the selectedpagechage or whatever) to remedy this?

JP
gleznovAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tusharashahCommented:
Paging is not completely automatic in DataGrid. After setting allowpaging to true you still need to set following Event in your codebehind:

Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs)
 DataGrid1.CurrentPageIndex = e.NewPageIndex
 BindGrid()
End Sub

-tushar
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gleznovAuthor Commented:
I've got:

    Private Sub DBGrid1_PageIndexChanged1(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DBGrid1.PageIndexChanged
        DBGrid1.EditItemIndex = -1
        DBGrid1.CurrentPageIndex = e.NewPageIndex
        'DBGrid1.DataSource = 'the datasrouce
        DBGrid1.DataBind()
    End Sub

Do I need something else in there?

JP
0
tusharashahCommented:
You do not need to comment out following line

DBGrid1.DataSource = the datasrouce

rest is fine and good to go..

-tushar
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

gleznovAuthor Commented:
Problem's still there though.  When I go to page two, click on button in the first row, it returns that it's from index 0.  Am I supposed to use the page index with these somehow, such that:

page 1 gives:  1st button = 0, 2nd button = 1 ... 5th button = 4
page 2 gives: 1st button = 5, etc

by using a formula?  (right now it's saying 1st button on page two = 0)

Maybe like:

selectedIndex = pageNumber * 5 + index given by button?

JP
0
gleznovAuthor Commented:
selIndex = (5 * (Session("GridPage")) + DBGrid1.SelectedIndex)

Is working.  I just set the session variable in pageindexchanged:

  Private Sub DBGrid1_PageIndexChanged1(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DBGrid1.PageIndexChanged
        DBGrid1.EditItemIndex = -1
        DBGrid1.CurrentPageIndex = e.NewPageIndex
        Session("GridPage") = e.NewPageIndex
        DBGrid1.DataSource = DS_UserSetup1
        DBGrid1.DataBind()
    End Sub

Then in the selectedIndexChanged I use the above expression to calculate the row chosen.

JP
0
tusharashahCommented:
You can do that, or you can retrieve some Column information from your DataGrid like following:

DataGrid1.SelectedItem.Cells(0).Text

This will give you 1st Column value of Selected Row.
Usually, I keep my 1st column with Unique Number and than set it to invisible. So, that you can access those data uniquely.

-tushar
0
tusharashahCommented:
selectedIndex = pageNumber * 5 + index
should better be replaced by:

(DataGrid1.PageSize * DataGrid1.CurrentPageIndex) + index

-tushar
0
tusharashahCommented:
Grade C! that's harsh


0
gleznovAuthor Commented:
Sorry Tush, that was a mistake.  I've written to the staff to correct that.

JP
0
tusharashahCommented:
Thank you JP.. that will surely encourage me to answer more & better!

-tushar
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.