Solved

Scrolling and Column Resizing using GridView with AutoGenerated Columns

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 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

16 Experts available now in Live!

Get 1:1 Help Now