LinkButton in Page Footer problem

Ask a Question related to ASP.NET Data Grid Control, Design and Development.

  1. #1

    Default LinkButton in Page Footer problem


    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


    Michael Combs Guest

  2. Similar Questions and Discussions

    1. Problem with LinkButton and AddAttributesToRender
      Hi, I'm trying to design a custom LinkButton. It inherits LinkButton as I need the implementation of the Click event (and I don't know how to...
    2. Page #s in Footer - change the start number? How?
      I'd like the page numbers that appear in the footer to start at a number other than 1. I can see easily how to do this for the PDF pages (on the...
    3. Need footer at page bottom, not just below content.
      Hi to all. What would be the procedure for having a footer that shows up at the bottom of the users browser as opposed to just being right below...
    4. Page Footer
      Darrell tat wo schreiben: With something like PHP or SSI (Server Side Includes). Try to rename the main file to *.shtml so that the server...
    5. LinkButton and page error in datagrid
      A LinkButton in a datagrid opens a new window, when clicked. Then clicking on the next page number in the datagrid raises the following error: ...
  3. #2

    Default Re: LinkButton in Page Footer problem


    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


    Michael Combs Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139