473,398 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

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 1964
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
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
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
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
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
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
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
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
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
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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,...
0
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...

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.