Link to home
Start Free TrialLog in
Avatar of gleznov
gleznov

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of tusharashah
tusharashah

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gleznov
gleznov

ASKER

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
You do not need to comment out following line

DBGrid1.DataSource = the datasrouce

rest is fine and good to go..

-tushar
Avatar of gleznov

ASKER

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
Avatar of gleznov

ASKER

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
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
selectedIndex = pageNumber * 5 + index
should better be replaced by:

(DataGrid1.PageSize * DataGrid1.CurrentPageIndex) + index

-tushar
Grade C! that's harsh


Avatar of gleznov

ASKER

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

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

-tushar