kpbarem
asked on
How to change column width for gridview
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
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
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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="gvPolicyDa ta_RowData Bound"
OnPageIndexChanging="gvPol icyData_Pa geIndexCha nging" 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
<asp:GridView ID="gvPolicyData" runat="server" OnRowDataBound="gvPolicyDa
OnPageIndexChanging="gvPol
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
ASKER
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.
Hi from 2018. Thank u so much! I killed 3 hours to solve that stupid problem.
ASKER
<asp:GridView ID="gvPolicyData" runat="server" OnRowDataBound="gvPolicyDa
OnPageIndexChanging="gvPol
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.