Gridview Fixed Height When Last Page Does Not Have Full Records

Posted on 2007-07-29
Last Modified: 2009-12-23
Hi there.  Please can someone let me know how you can ensure that the GridView always maintains the same height, and the paging controls maintain the same position when the last page of a dataset has less records than defined per page.  For example, if my data has 52 records and I define paging every 10 records, the last page will only have 2 records so the paging controls will jump up rather untidily.  I am guessing I would need to insert some extra rows when a certain event fires but cannot get the right code to work (the correct event and the count logic?).  Thank you for your time.
Question by:antdow
    LVL 22

    Expert Comment

    LVL 96

    Expert Comment

    by:Bob Learned
    If you are using paging, then when the page is full what is the height for the grid?  If you set the height for the grid to that height, then the grid will stay that height, instead of auto-sizing when the page isn't full.

    LVL 10

    Expert Comment

    Put your Datagrid Into DIV tag

    <DIV style="OVERFLOW: auto; HEIGHT:
    <asp:DataGrid ........>

    for More details plz Hit

    Thanks & Regards
    LVL 1

    Author Comment

    Thanks for the initial feedback.  Whilst the suggested solutions to fix the height of the GridView indeed do that, the row heights increase in size to compensate so the overall effect is not too desirable.  DarkoLord's referred solution looks on the right track but having a little difficulty converting from C# to VB.  What I have so far is...

        Protected Sub EventsGrid_DataBound(ByVal sender As Object, ByVal e As System.EventArgs)
            If EventsGrid.PageIndex + 1 = EventsGrid.PageCount Then
                Dim RowLoop, ColLoop As Integer
                For RowLoop = 1 To EventsGrid.PageSize - EventsGrid.Rows.Count
                    Dim NewRow = New GridViewRow(0, 0, DataControlRowType.DataRow, DataControlRowState.Normal)
                    For ColLoop = 1 To EventsGrid.Columns.Count
                        NewRow.Controls.Add(New TableCell())
                    '**********Add Row Here?**********
            End If

    However I cannot seem to find the correct syntax for adding the new rows to the grid?

    Please can someone assist?
        End Sub
    LVL 22

    Accepted Solution

    EventGrid.Controls(0).Controls.AddAt(EventGrid.Controls(0).Controls.Count - 1, NewRow)
    LVL 1

    Author Comment

    Genius - cheers Darko.  The C# example had square brackets - seems to be the only different in this particular part of the solution - and I missed it.  Thanks for your time, the points are yours.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now