Encountering Problems with Datagrid Paging

mike55

Contributor
Joined
Mar 26, 2004
Messages
727
Location
Ireland
Hi,

Am trying to do paging at the moment, here is the code that I am using:
Code:
Sub page_Datagrid(ByVal o As Object, ByVal e As DataGridPageChangedEventArgs)
        dgMembers.CurrentPageIndex = e.NewPageIndex
        dgMembers.DataSource = dsDataset.Tables("Members")
        dgMembers.DataBind()
    End Sub

In the Html section of my data grid I have added the following
Code:
OnPageIndexChanged="page_Datagrid"

However when I select a new page on the datagrid, the grid simple disappears.

Any suggestions on what is causing this problem??

Mike55
 
wessamzeidan said:
where does dsDataset come from?

Code:
 Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        If Not Page.IsPostBack Then
            fillDataGrids()
        End If
    End Sub

Code:
 Private Sub fillDataGrids()
        Try
            Dim daDataAdapter As New SqlDataAdapter


            connect()
            MyCommand.CommandType = CommandType.Text
            MyCommand.CommandText = "SELECT Distinct myMembers.Member_ID, myMembers.Surname, myMembers.Forename, myMembers.DOB, myGroupMembership.Org_ID" & _
                                                            " FROM myMembers INNER JOIN" & _
                                                                " myGroupMembership ON myMembers.Member_ID = myGroupMembership.Member_ID CROSS JOIN Org_MemberShip" & _
                                                            " WHERE myGroupMembership.Org_ID = 'ST466C513'"
            daDataAdapter = New SqlDataAdapter(MyCommand)
            daDataAdapter.Fill(dsDataset, "Members")

            MyCommand.CommandType = CommandType.Text
            MyCommand.CommandText = "SELECT Distinct myGroups.Group_ID, myGroups.Group_Name, myGroups.Group_Description" & _
                                                            " FROM myGroups where myGroups.Org_ID= 'ST466C513' ORDER BY myGroups.Group_ID"
            daDataAdapter = New SqlDataAdapter(MyCommand)
            daDataAdapter.Fill(dsDataset, "Groups")

            MyConnection.Close()

            dgMembers.DataSource = dsDataset.Tables("Members")
            dgMembers.DataBind()

            dgGroups.DataSource = dsDataset.Tables("Groups")
            dgGroups.DataBind()
        Catch ex As Exception
            Throw ex
        Finally
            MyConnection.Close()
        End Try
    End Sub
 
Ok, then you can do this

Sub page_Datagrid(ByVal o As Object, ByVal e As DataGridPageChangedEventArgs)
dgMembers.CurrentPageIndex = e.NewPageIndex
fillDataGrids()
End Sub
 
Yea it works, thanks.

But why must I go back to the database in order for paging to work correctly. Since the system has to go back and reload the data this screws up what I am doing.
 
Because you have to rebind to the datasource each time you change the page in the datagrid, so the datatable should be filled. What you can do is when you fill the dataset for the first time, put it in the session and then use it when binding again.
 
Have being working on the idea of putting the dataset into a session and then bindin the session everytime, but the datagrid is still refilling.

Mike55
 
Back
Top