Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 230
  • Last Modified:

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
0
gleznov
Asked:
gleznov
  • 6
  • 4
1 Solution
 
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
 
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now