Datagrid -width of a column

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a datagrid and i'm trying to fix the width of one of the columns to be
exactly 300px. My problem is that one of the records fields(CompanyName) is
really long and has no spaces so it streches the whole datagrid accross the
screen. Has anyone else ever experienced this problem and is there any way of
fixing it. Basically my datagrid is streching to about 120% because of this
one record. Would love to work out how I can change this setting. Any
suggestions or help at all would be appreciated.

EXAMPLE CODE:
<asp:Table Width="500px" BorderWidth="1px">
<asp:TableRow>
<asp:TableCell Width="500px">
<asp:DataGrid id="MyDataGrid" runat="server" Width="450px"
AllowPaging="True" AllowSorting="True" PageSize="5"
AutoGenerateColumns="false" DataKeyField="SupplierID"
AllowCustomPaging="True" ShowFooter="True">
<Columns>
<asp:BoundColumn Visible="False" DataField="SupplierID"
HeaderText="SupplierID">
<HeaderStyle Height="20px" Width="60px"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="CompanyName" ReadOnly="True" HeaderText="Company
Name">
<HeaderStyle Height="20px" Width="300px"></HeaderStyle>
</asp:BoundColumn>
 
I use a css style for my repeater controls, but you can make it work with a
datagrid by using the style attributes in the column template or by adding it
dynamically if you are building your datagrid on the fly:

e.Item.Cells([INDEX]).Style.Add("word-wrap", "break-word")
e.Item.Cells([INDEX]).Attributes.Add("width", "250px")

<style type="text/css">TABLE#tableName { TABLE-LAYOUT: fixed }
TD.url { WORD-WRAP: break-word }
</style>

where #tableName is the name of your table and TD.XXX(url in my case) is the
column to break

might help...
 
Back
Top