LinkButton in Page Footer problem

M

Michael Combs

I am modifying the paging ListItem footer in a datagrid in the ItemCreated
event. I'm adding another cell in which I place a 'Show All' LinkButton. So
far so good. The problem is that when the LinkButton is clicked and the page
is rendered again the grid renders one less row each time. Continually
clicking the button eventually shrinks the grid to having zero rows. I have
no code in the ItemCommand event of the datagrid and do not have a separate
LinkButton Click event handler. The ItemCreated code is below. Anyone have
any ideas?

Thanks,
Michael

Private Sub grid_ItemCreated(ByVal sender As System.Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles grid.ItemCreated

If e.Item.ItemType = ListItemType.Pager Then

Dim cell As TableCell
Dim pagerRow As TableCellCollection = e.Item.Cells
Dim pagerCell As TableCell = pagerRow(0)
Dim pageCounter As TableCell = New TableCell()
Dim showall As LinkButton = New LinkButton()

pagerCell.ColumnSpan = pagerCell.ColumnSpan - 1
pageCounter.HorizontalAlign = HorizontalAlign.Right
pageCounter.BorderStyle = BorderStyle.None

showall.ID = "ShowAll"

If _showall Then
showall.Text = "Show Pages"
Else
showall.Text = "Show All"
End If

'AddHandler showall.Click, AddressOf ShowAll_Click

pageCounter.Controls.Add(showall)
pagerRow.AddAt(1, pageCounter)

End If

End Sub
 
M

Michael Combs

I've discovered that the code in my prerender event is causing the problem.
I am adding a 'super' header to my datagrid in the prerender event. I'm
creating a new DataGridItem, adding a new cell which contains a LinkButton.
I'm just displaying some text across the top of my datagrid with a 'Home'
button.

The problem is that each click of the button (or any other postback to the
grid) causes the data rows(grid bound to dataview) to offset by 1 row. More
simply put, it appears that a blank row is being adding to the top of the
list of data rows. This blank row is inserted below the header I add but
above the rest of the data rows. I've included the source of my prerender
event below. The statement that causes the offset is
grid.Controls(0).Controls.AddAt.. It appears that this statement is
incrementing some starting offset in the grid that is being maintained in
the viewstate. Anyone have any ideas on a solution?

Private Sub grid_PreRender(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles grid.PreRender

Dim di As DataGridItem = New DataGridItem(0, 0, ListItemType.Header)
Dim cell As TableCell = New TableCell()

di.ID = "header"
di.CssClass = "pager"

' page cell
cell.ColumnSpan = 1
di.Cells.Add(cell)

' home cell
cell = New TableCell()
cell.HorizontalAlign = HorizontalAlign.Right
cell.ColumnSpan = grid.Columns.Count - 1
cell.Text = "<a href=ProvAudit.asp>Home</a>"
di.Cells.Add(cell)

' adding a header above the top pager causes the pager
' to become visible regardless of intention
If grid.PagerStyle.Position = 1 OrElse _
grid.PagerStyle.Position = 2 OrElse _
Not grid.AllowPaging Then
grid.Controls(0).Controls.AddAt(0, di)
Else
grid.Controls(0).Controls.AddAt(1, di)
End If
End Sub

Michael Combs
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top