Format datagrid columns

T

ton

when adding PagerStyle.Mode = PagerMode.NumericPages, I receive all page
number in the footer of the datagrid. Next and prev shows that other pages
are displayed, but the data shown on the screen does not change.
 
A

Alessandro Zifiglio

are you sure you want to use custom next previous buttons. The reason i ask
this is because the datagrid already provides you with default next previous
buttons. However you want custom next/previous buttons and this is what i
note from your code. These buttons are added dynamically, so you probably
defined the click event handlers for both. Can you showcase this code, and
what you are doing in the click event handlers. I suspect your problem to be
here. Also note that if your using custom controls for the paging whereas to
the built in paging controls then you need to hookup the eventhandlers for
your next/previous buttons properly. From your code i see one handler,
however how is this one handler called. I suspect the problem to be here :

For a nice example look at the msdn code here which has
NextPage/previousPage/LastPage/FirstPage buttons and how they have
implemented this. See how that one handler handles clicks for all four
buttons.

http://msdn.microsoft.com/library/d...cifyingPagingBehaviorInDataGridWebControl.asp
 
T

ton

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
 
A

Alessandro Zifiglio

Ok, i was under the impression that you were using custom buttons and not
the built in buttons of the datagrid pager. I am unable to note anything
unusual at first look. Your on your own with this one ton. Wish i could help
more ;P
 
T

ton

SOLVED
The reason lies in the sequence of the instructions. At the start of the
procedure I set the datasource property (which was one of the last
instructions). Second I've changed the seuence of these lines of code
Controls.Add(label)

Controls.Add(Datagrid)

AddHandler Datagrid.PageIndexChanged, AddressOf Me.nextprev

Datagrid.DataBind()

I do not no which line made the right step, but I can imagine that the
databound after the controls.add can have helped.

Many Thanks Alessandro

Ton
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top