Geeks With Blogs
Bunch's Blog One day I'll have a catchy subtitle, one day

Here is an old trick to get vertical scroll bars for a GridView. I find this handy when the end users do not want paging but they also do not want to have a page load a GridView that is a mile long either. The code below shows placing your GridView inside a Panel. The Panel is where the scroll bar option is set. I used “Auto” in the example, this way the scroll bar will only appear if the amount of rows in the GridView exceeds the height set. The trick lies in placing both controls inside a single cell of a regular old HTML table. This keeps the scroll bar next to the GridView and makes it look like a single control.

<table>
   <tr>
        <td>
            <asp:Panel ID="pnlGridView" runat="server" ScrollBars="Auto" Width="100%" Height="350px">
                <asp:GridView ID="gvData" runat="server">
                    your GridView items
                </asp:GridView>
            </asp:Panel>
        </td>
    </tr>
</table>

One thing I have seen is that occasionally the scroll bar will make some of the GridView columns narrower than you may want. This in turn can make each row higher than you would like and then display less rows on the screen. The way to work around this is to set the widths of the columns in the GridView.

Technorati Tags: ,,
Posted on Monday, February 8, 2010 12:19 PM | Back to top


Comments on this post: Vertical Scroll Bars For GridView

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Bunch | Powered by: GeeksWithBlogs.net