Scrollbars on a GridView

I had a GridView on one of my sites, Mapping My Life, that was overflowing that graphic in which I wanted to contain it. I poked around for how to put scrollbars on a GridView, but alas, you can’t do that. But, I did find a site that explains how to get around this by wrapping the GridView inside a Panel. And it worked just like a wanted it to. The key pieces are to set the Height and ScrollBars properties of the Panel: Nothing too fancy, but exactly what I needed.

<asp:Panel ID="pnlLocations" Height="200" ScrollBars="Vertical" runat="server">
    <asp:GridView ID="grdLocations" AutoGenerateColumns="false" Font-Size="10" DataKeyNames="LocId" Height="300" runat="server">
        <Columns>
            <asp:BoundField DataField="Field1" HeaderText="Description" ItemStyle-Width="320" />
            <asp:BoundField DataField="Field2" HeaderText="City" ItemStyle-Width="135" ItemStyle-HorizontalAlign="Center" />
            <asp:BoundField DataField="Field3" HeaderText="User Name" ItemStyle-Width="160" ItemStyle-HorizontalAlign="Center" />
        </Columns>
    </asp:GridView>
</asp:Panel>

Nothing too fancy, but exactly what I needed.

Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: