No. I just want to scroll page by page and the default paging behaviour with
a next prev butto is fine for me. BUT this does not work. I receive an event
when clicking on the > (=next button), there was no event when pressing on
the < (prev) button. The next page is displayed, and the currentpageindex
changes because of the e.NewPageIndex.
When clicking on < or > the procedure createchildcontrols is both called,
only by the next event the NextPrev procedure is called and executed,
without any result. So the prev button is enabled after the first next page,
but after clicking it does not lead to a NewPageIndex event.
Here my code: First the ShowGrid procedure: It is called from
createchildcontrols, with the parameters, which are stored as session
variable.
Public Function ShowGrid2(ByVal TableID As dbOLEserver.dbTableNum, ByVal
TopID As Integer, ByVal TopTableID As dbOLEserver.dbTableNum, Optional ByVal
Query As String = "", Optional ByVal startpage As Integer = 0) As Boolean
Dim label As New Label, nSide As dbOLEserver.nSide, ses As New
dbOLEserver.Session
Dim col As ButtonColumn, col2 As BoundColumn, col3 As DataGridTextBoxColumn
'
label.ID = "X"
label.Text = "test"
Dim Datagrid As DataGrid, SQLdataAdapter As SqlDataAdapter, SQLconnection As
SqlConnection
Dim dataset As DataSet, Connect As String
Connect = GetState("adoconnect")
SQLconnection = New SqlConnection(Connect)
Query = ses.TableName(TableID)
If TopID > 0 Then
Query = "v" + CStr(TopTableID) + Query + " " + CStr(TopID)
Else
Query = "v0" + Query
End If
SQLdataAdapter = New SqlDataAdapter(Query, SQLconnection)
dataset = New DataSet
SQLdataAdapter.Fill(dataset)
Datagrid = New DataGrid
With Datagrid
..ID = "GRID" + ClientID
..GridLines = GridLines.Both
..VirtualItemCount = 200
..PageSize = 5
..AutoGenerateColumns = False
..AllowPaging = True
..PagerStyle.Mode = PagerMode.NextPrev ''NumericPages
..PagerStyle.PageButtonCount = 5
..AllowCustomPaging = False
..AllowSorting = False
..BorderStyle = BorderStyle.Solid
..DataKeyField = "ID"
..GridLines = GridLines.Both
End With
col = New ButtonColumn '' BoundColumn
col.HeaderText = "ID"
col.ButtonType = ButtonColumnType.PushButton
col.HeaderStyle.Wrap = False
col.CommandName = "Card"
col.Text = "Edit"
col.ItemStyle.Wrap = False
col.ItemStyle.HorizontalAlign = HorizontalAlign.Center
col.ItemStyle.Width = Unit.Pixel(80)
Datagrid.Columns.Add(col)
AddHandler Datagrid.ItemCommand, AddressOf Me.DataGridCard
col2 = New BoundColumn
col2.HeaderText = ""
col2.DataField = dataset.Tables(0).Columns(0).ColumnName
col2.Visible = False
Datagrid.Columns.Add(col2)
Dim i As Integer
For i = 2 To dataset.Tables(0).Columns.Count - 1
col2 = New BoundColumn
col2.HeaderText = dataset.Tables(0).Columns(i).ColumnName
col2.DataField = dataset.Tables(0).Columns(i).ColumnName
col2.ItemStyle.Wrap = False
col2.ItemStyle.Font.Bold = Me.Font.Bold
col2.ItemStyle.Font.Italic = Me.Font.Italic
col2.ItemStyle.HorizontalAlign = HorizontalAlign.Left
Datagrid.Columns.Add(col2)
Next
AddHandler Datagrid.PageIndexChanged, AddressOf Me.nextprev
Datagrid.DataSource = dataset
Datagrid.DataBind()
label.Text = Query + " page " '' + Str(_Page) ''(1).HeaderText ''Visible =
False
Controls.Add(label)
Controls.Add(Datagrid)
End Function
Private Sub nextprev(ByVal sender As Object, ByVal e As
DataGridPageChangedEventArgs)
Dim dg As DataGrid, x As Label
dg = CType(sender, DataGrid)
dg.CurrentPageIndex = e.NewPageIndex
dg.DataBind()
x = FindControl("X")
x.Text = "Xpage " + CStr(e.NewPageIndex)
End Sub