Solved

How to change column width for gridview

Posted on 2012-12-28
5
955 Views
Last Modified: 2013-01-02
This sounds very simple but I'm kindof at my wits end with it.  I have a gridview in which a new column was added thats causing it to look too wide on my web page.  All of the columns are asp:BoundField.  Here is what I have tried to no avail.

1) Changing the item style width for the columns
2) Changing the header style width for the columns
3) Changing the control style width for the columns.
4) Changing the width of the entire grid view.
5) Changing the width of the container inside of the gridview.
6) Moving the gridview outside of the container and making the width smaller.
7) Placing the gridview inside of a div and styling that to an arbitrarily small size.


None of  these seem to effect the width of it.  This is very weird to me.  I seem to be able to effect the width of the content inside of the column but not the column itself.  I can't figure out anywhere in the code that is making the column as wide as it is.  I've attached an image of the gridview as is.  Right now, the entire gridview is sized to an arbitrary small width, the columns are all sized to a smaller width and it is inside of a container that is sized to an arbitrary small width.  All of these seem to have no affect.  It is still too wide.

Any ideas?  Am I missing something simple?

Thanks in advance!
GridViewIssue.png
0
Comment
Question by:kpbarem
  • 3
5 Comments
 
LVL 27

Assisted Solution

by:Chinmay Patel
Chinmay Patel earned 250 total points
ID: 38727702
Did you try these 2 together?
1) Changing the item style width for the columns
2) Changing the header style width for the columns
0
 
LVL 1

Accepted Solution

by:
Omar_El_Sergany earned 250 total points
ID: 38727757
all you need to set the header size for each column

it can be fixed number or %

example for asp page :
 
 <asp:BoundField DataField="Status" HeaderText="Status" ReadOnly="True" SortExpression="Status" >
            <HeaderStyle Width="10%" />
            </asp:BoundField>

Open in new window

0
 

Author Comment

by:kpbarem
ID: 38727813
<div style="width: 200px;">            
            <asp:GridView ID="gvPolicyData" runat="server" OnRowDataBound="gvPolicyData_RowDataBound"
                OnPageIndexChanging="gvPolicyData_PageIndexChanging" AutoGenerateColumns="False"
                 Height="160px" AllowSorting="True" BorderStyle="None" CellPadding="5" Width="50%">
                <Columns>            
                    <asp:BoundField DataField="Policy_ID" HeaderText="Policy_ID" SortExpression="Policy_ID"
                        Visible="False" />
                    <asp:BoundField DataField="Policy_TEXT" HeaderText="Text" ReadOnly="True">
                        <HeaderStyle BackColor="#DFDFDF" Font-Bold="True" ForeColor="Navy" VerticalAlign="Bottom" Width="5%"/>
                        <ItemStyle Width="5%" />
                        <ControlStyle Width="5%" />
                    </asp:BoundField>


None of these things seem to be making any difference.
0
 

Author Comment

by:kpbarem
ID: 38727922
I think the weird thing is that the column information will wrap and resize but the column itself won't.  As an example heres PART of my code for this gridview setting the grid at a particular size inside of a div that is a particular size and a column set at a particular size.

        <asp:GridView ID="gvPolicyData" runat="server" OnRowDataBound="gvPolicyData_RowDataBound"
                OnPageIndexChanging="gvPolicyData_PageIndexChanging" AutoGenerateColumns="False"
                 Height="160px" AllowSorting="True" BorderStyle="None" CellPadding="5" Width="50%">
                <Columns>            
                    <asp:BoundField DataField="Policy_ID" HeaderText="Policy_ID" SortExpression="Policy_ID"
                        Visible="False" />
                    <asp:BoundField DataField="Policy_TEXT" HeaderText="Text" ReadOnly="True">
                        <HeaderStyle BackColor="#DFDFDF" Font-Bold="True" ForeColor="Navy" VerticalAlign="Bottom" Width="100px"/>
                        <ItemStyle Width="100px" />
                        <ControlStyle Width="100px" />
                    </asp:BoundField>

Attached is the picture of what that looks like.
GridViewExpandingColumn.png
0
 

Author Comment

by:kpbarem
ID: 38737630
Ok, so heres what the problem was.  In my gridview some of the databound columns contained long links or other text without spaces.  This causes the word wrap to not wrap and pushes the whole column out despite what size I specify.  So what I had to do was add some spaces in those long sequences of text to force a word wrap.  Now it is sized properly.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

813 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

18 Experts available now in Live!

Get 1:1 Help Now