Solved

Scrolling and Column Resizing using GridView with AutoGenerated Columns

Posted on 2014-10-29
1
793 Views
Last Modified: 2014-11-07
I am trying to use a GridView control in an ASP.NET/C# project with the AutoGenerateColumns="true".  The data loads into the GridView but I am having two issues.  First issue is that I am unable to get the GridView to scroll horizontally.  It seems that it is just stuffing all the data into the GridView and not expanding.   Second issue is that I am unable to re-size the columns to fit the data. I have feeling that one of these issues may be causing the other.

<asp:Panel ID="Panel2" runat="server" CssClass="panel" Width="100%" ScrollBars="Horizontal">
        <div class="grid" style="width: 100%; overflow: auto;">
            <asp:GridView ID="grdProductionResorces" runat="server" AutoGenerateColumns="True"   OnRowDataBound="grdProductionResorces_OnRowDataBound"
                OnRowCreated="grdProductionResorces_RowCreated"
                BorderStyle="None" BorderWidth="1px" CellPadding="3" BackColor="White" BorderColor="#999999" GridLines="Vertical" CssClass="dataGridTable th">
                <AlternatingRowStyle BackColor="#DCDCDC" />
                <Columns>
                </Columns>
                <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
                <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
                <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
                <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
                <SortedAscendingCellStyle BackColor="#F1F1F1" />
                <SortedAscendingHeaderStyle BackColor="#0000A9" />
                <SortedDescendingCellStyle BackColor="#CAC9C9" />
                <SortedDescendingHeaderStyle BackColor="#000065" />
            </asp:GridView>
        </div>
    </asp:Panel>
0
Comment
Question by:WH_Tech
1 Comment
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 40415702
I'm not sure but I think you just want to disable text wrapping. You shouldn't need the extra div (I'm guessing you added that for testing). Try this:
    <asp:Panel ID="Panel2" runat="server" CssClass="panel" Width="100%" ScrollBars="Horizontal">
            <asp:GridView ID="grdProductionResorces" runat="server" AutoGenerateColumns="True" OnRowDataBound="grdProductionResorces_OnRowDataBound"
                OnRowCreated="grdProductionResorces_RowCreated"  
                BorderStyle="None" BorderWidth="1px" CellPadding="3" BackColor="White" BorderColor="#999999" GridLines="Vertical" CssClass="dataGridTable th">
                <AlternatingRowStyle BackColor="#DCDCDC" />
                <Columns>
                </Columns>
                <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
                <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
                <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
                <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
                <SortedAscendingCellStyle BackColor="#F1F1F1" />
                <SortedAscendingHeaderStyle BackColor="#0000A9" />
                <SortedDescendingCellStyle BackColor="#CAC9C9" />
                <SortedDescendingHeaderStyle BackColor="#000065" />
                <RowStyle Wrap="false" />
            </asp:GridView>
    </asp:Panel>

Open in new window

So the <RowStyle> makes sure the content pushes the cell width to the right. Your panel already supports horizontal scrolling so that should be enough.
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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

790 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