LinkButton in Page Footer problem

Discussion in 'ASP .Net Datagrid Control' started by Michael Combs, Jan 13, 2004.

  1. 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, Jan 13, 2004
    #1
    1. Advertising

  2. 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, Jan 13, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sathyaish
    Replies:
    3
    Views:
    3,079
    Sathyaish
    Sep 8, 2005
  2. VT
    Replies:
    8
    Views:
    1,674
    Paul E. Schoen
    Oct 14, 2010
  3. Sathyaish

    Linkbutton does not look like a linkbutton

    Sathyaish, Sep 8, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    171
    Sathyaish
    Sep 8, 2005
  4. Henrik
    Replies:
    1
    Views:
    416
    Ken Cox [Microsoft MVP]
    Jul 6, 2006
  5. Martin Strojek

    Problem adding dynamic LinkButton[] Array with event to a page

    Martin Strojek, Nov 9, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    345
    Martin Strojek
    Nov 9, 2004
Loading...

Share This Page