Link to home
Start Free TrialLog in
Avatar of kpbarem
kpbarem

asked on

How to add a scrollbar to a gridview in asp.net

How can I specify a height for my gridview and add a scrollbar to it?  Is there a setting i'm missing on it?
Avatar of Paul Jackson
Paul Jackson
Flag of United Kingdom of Great Britain and Northern Ireland image

Put the Gridview inside a Panel or Divs :

<asp:Panel ID="myPanel" runat="server" ScrollBars="Both" Height="500" Width="100%">
 <asp:GridView ID="myGridView" runat="server">
 </asp:GridView>
</asp:Panel>

<div style="width:100%; height:500; overflow:auto;">
<asp:GridView ID="myGridView" runat="server">
</asp:GridView>
</div>
Avatar of kpbarem
kpbarem

ASKER

This is my solution at the moment.  The only issue that I see with this is that the grid shows a list of search results.  If the search returns only one item and you have a panel or div that is specified at 500px then you will see a disabled scrollbar of 500 px at the side of the grid.  

The only solution on this I can determine is to check the amount of rows in the grid and possibly set the panel size dynamically based on the amount of rows in the grid for the first 5 rows or so and then just set it at 500px after that.  That's not really a perfect solution though.
ASKER CERTIFIED SOLUTION
Avatar of Paul Jackson
Paul Jackson
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kpbarem

ASKER

Nice! I should have seen that.  Thank you!!