Solved

Scrolling and Column Resizing using GridView with AutoGenerated Columns

Posted on 2014-10-29
1
746 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access properties in nested observable collections 8 23
ASP.net VB.net Load contents of a GridView  to Excel 2 27
Server Error 11 47
Angular - break the dataset in chunks? 7 38
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

932 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now