• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2034
  • Last Modified:

Gridview Fixed Height When Last Page Does Not Have Full Records

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.
0
antdow
Asked:
antdow
1 Solution
 
Bob LearnedCommented:
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.

Bob
0
 
SystemExpertCommented:
Put your Datagrid Into DIV tag

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

for More details plz Hit http://www.codeproject.com/aspnet/DataGridFixedHeader.asp?df=100&forumid=170262&exp=0&select=1988288

Thanks & Regards
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
antdowAuthor Commented:
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())
                Next
                '**********Add Row Here?**********
            Next
        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
0
 
DarkoLordCommented:
EventGrid.Controls(0).Controls.AddAt(EventGrid.Controls(0).Controls.Count - 1, NewRow)
0
 
antdowAuthor Commented:
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.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now