473,508 Members | 2,333 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Datagrid -width of a column

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>
Jul 21 '05 #1
1 1976
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...

"Stephen" wrote:
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>

Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2887
by: GregM | last post by:
I have a read only datagrid that is designed to coordinate itself with textboxes. When the user clicks on a row in the datagrid, detailed data for that row is displayed for editing in the...
5
9165
by: BBFrost | last post by:
Win2000 ..Net 1.1 SP1 c# using Visual Studio Ok, I'm currently in a "knock down - drag out" tussle with the .Net 1.1 datagrid. I've come to realize that a 'block' of rows highlighted within...
0
1651
by: mgenti | last post by:
I am experiencing a problem when I add a row to a DataTable that is used on a DataGrid in my Windows Form application. When I add a new row I no longer get a response from my form. I see the row...
3
5020
by: Ryan Liu | last post by:
Hi there, I got a NullReferenceException when delete last row in a datagrid. I had hard time to solve since it does not occur in my own code. I put a datagrid in my inherited user control,...
0
1311
by: BK Kim | last post by:
Hello. I am trying to use dataGrid in a dataGrid, meaning first DataGrid displays some information and on each row, it is going to have another datagrid to display detailed information. I was...
4
3477
by: tshad | last post by:
I am having trouble with links in my DataGrid. I have Links all over my page set to smaller and they are consistant all over the page in both Mozilla and IE, except for the DataGrid. Here is a...
4
7351
by: Suzanne | last post by:
Hi all, I'm having problems with datagrids and the currentcellchanged event. My problem is this: I have a datagrid on a form, if the user changes the text in a cell on the datagrid then tries to...
7
5656
by: Dave | last post by:
Are there any add-on products or samples available that can do the following in an vb.net datagrid I want to compare 2 rows in a datagrid - one row from one database and another row for another...
9
2708
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using EditCommandColumn in the DataGrid. This is the...
8
3052
by: Brock | last post by:
I am trying to populate a Crystal Report from data in my DataGrid. The reason for this is that I want the user to be able to change values without updating the database, but still have their report...
0
7123
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7324
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7382
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7495
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5627
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5052
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.