Scrollable datagrid: dynamic paging

R

RJN

Hi

Sorry for posting again.

I have a datagrid which is put inside a div tag to make it scrollable. I
need to page the datagrid. The page numbers appear at the bottom of the
datagrid and has to be scrolled down completely to see the page number
links. The page number should always be visible outside the scroll bar.
Basically I want to create the paging links dynamically and on click of
this it should fire PageIndexChanged event.

The following link has an example of scrollable/sortable datagrid. I'm
trying to paging in the similar way.
http://www.extremeexperts.com/Net/Articles/ScrollableDataGridwithSorting
.aspx

I introduce a table below the datagrid and this table will have all the
paging links.

In the ItemCreated event of the datagrid, I get the control collection
of the paging links and add it to the table.

If e.Item.ItemType = ListItemType.Pager Then
Dim i As Int16
For i = 0 To e.Item.Controls(0).Controls.Count - 1
--Create a new link button
--Get the e.Item.Controls(0).Controls(i) and assign
its properties to link button
--Add the link button to the table
Next
End if

Now I need to assign the events to the new paging links created. It
should fire PageIndexChanged event.

To do this , in the ItemDataBound event I add the
Page.GetPostBackClientHyperlink to the link button .

But in ItemDataBound I'm not able to execute the statements within the
below if condition.
If e.Item.ItemType = ListItemType.Pager

End if

This statement is not executed at all.

Any help is appreciated.

Regards

RJN
 
S

Saravana

Hi RJN,

Item_DataBound event will fire only if you do databinding in that datagrid.
If you send your code behind code, then it will be easier to find the issue.
 
R

RJN

Hi Sarvana

Thanks for your reply. We have followed the similar approach that you
have given in one of your articles. In the ItemCreated event we created
all the links and in the ItemDataBound event we attached the events for
these links.

In the .aspx we have a created a table "tblPage" for showing the page
number links.

This is the code in .aspx.vb page in the ItemCreated event.

If e.Item.ItemType = ListItemType.Pager Then
tblPage.Rows(0).Cells.Clear()
For ipage = 0 To e.Item.Controls(0).Controls.Count - 1
strType = e.Item.Controls(0).Controls(ipage).GetType.FullName
tblcell = New TableCell
Select Case strType
Case "System.Web.UI.LiteralControl"
Dim ltPage As New LiteralControl
ltPage.ID =
e.Item.Controls(0).Controls(ipage).ClientID
ltPage.Text = " "
tblcell.Controls.Add(ltPage)
Case "System.Web.UI.WebControls.Label"
Dim lblPage As New Label
lblPage.CssClass = "MSPullDownContent"
lblPage.ID =
e.Item.Controls(0).Controls(ipage).ClientID
lblPage.Text =
CType(CType(e.Item.Controls(0).Controls(ipage), System.Web.UI.Control),
System.Web.UI.WebControls.Label).Text
tblcell.Controls.Add(lblPage)

Case "System.Web.UI.WebControls.DataGridLinkButton"
Dim lnkbutton As New LinkButton
Dim ctl As
System.Web.UI.WebControls.DataGridItem

lnkbutton.ID =
CType(e.Item.Controls(0).Controls(ipage),
System.Web.UI.Control).ClientID
lnkbutton.CommandArgument =
CType(CType(e.Item.Controls(0).Controls(ipage), System.Web.UI.Control),
System.Web.UI.WebControls.LinkButton).CommandArgument
lnkbutton.CommandName =
CType(CType(e.Item.Controls(0).Controls(ipage), System.Web.UI.Control),
System.Web.UI.WebControls.LinkButton).CommandName
lnkbutton.Text =
CType(CType(e.Item.Controls(0).Controls(ipage), System.Web.UI.Control),
System.Web.UI.WebControls.LinkButton).Text
lnkbutton.Style.Add("text-decoration", "none")
lnkbutton.Attributes.Item("onclick") =
Page.GetPostBackClientHyperlink(e.Item.Controls(0).Controls(ipage),
lnkbutton.CommandArgument)
tblcell.Controls.Add(lnkbutton)
End Select
tblPage.Rows(0).Cells.Add(tblcell)
Next


--In the Item databound event:

If e.Item.ItemType = ListItemType.Pager Then
Dim ipage As Int16
Dim strType As String

For ipage = 0 To e.Item.Controls(0).Controls.Count - 1
strType =
e.Item.Controls(0).Controls(ipage).GetType.FullName
If strType =
"System.Web.UI.WebControls.DataGridLinkButton" Then
Dim lnkbutton As LinkButton
Dim oControl As LinkButton
oControl = CType(e.Item.Controls(0).Controls(ipage),
System.Web.UI.WebControls.LinkButton)
lnkbutton =
tblpage.Rows(0).Controls(ipage).Controls(0)
lnkbutton.Style.Add("text-decoration", "none")
lnkbutton.Attributes.Add("href",
Page.GetPostBackClientHyperlink(e.Item.Controls(0).Controls(ipage), ""))
End If
Next
End If

The links are being created but events are not attached to them. Will
you be able to tell where we are doing wrong?

Regards

Rjn
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top