Solved

Scrolling and Column Resizing using GridView with AutoGenerated Columns

Posted on 2014-10-29
1
872 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

691 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