473,770 Members | 7,287 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(CompanyN ame) 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="1p x">
<asp:TableRow >
<asp:TableCel l Width="500px">
<asp:DataGrid id="MyDataGrid " runat="server" Width="450px"
AllowPaging="Tr ue" AllowSorting="T rue" PageSize="5"
AutoGenerateCol umns="false" DataKeyField="S upplierID"
AllowCustomPagi ng="True" ShowFooter="Tru e">
<Columns>
<asp:BoundColum n Visible="False" DataField="Supp lierID"
HeaderText="Sup plierID">
<HeaderStyle Height="20px" Width="60px"></HeaderStyle>
</asp:BoundColumn >
<asp:BoundColum n DataField="Comp anyName" ReadOnly="True" HeaderText="Com pany
Name">
<HeaderStyle Height="20px" Width="300px"></HeaderStyle>
</asp:BoundColumn >
Jul 21 '05 #1
1 1994
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("wo rd-wrap", "break-word")
e.Item.Cells([INDEX]).Attributes.Ad d("width", "250px")

<style type="text/css">TABLE#tabl eName { 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(CompanyN ame) 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="1p x">
<asp:TableRow >
<asp:TableCel l Width="500px">
<asp:DataGrid id="MyDataGrid " runat="server" Width="450px"
AllowPaging="Tr ue" AllowSorting="T rue" PageSize="5"
AutoGenerateCol umns="false" DataKeyField="S upplierID"
AllowCustomPagi ng="True" ShowFooter="Tru e">
<Columns>
<asp:BoundColum n Visible="False" DataField="Supp lierID"
HeaderText="Sup plierID">
<HeaderStyle Height="20px" Width="60px"></HeaderStyle>
</asp:BoundColumn >
<asp:BoundColum n DataField="Comp anyName" ReadOnly="True" HeaderText="Com pany
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
2910
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 textboxes. The datagrid and textboxes are populated from the same underlying SQL Server table but using different strongly typed data adapters and datasets for display and editing. So I coordinate syncronization of the two sets of data using code. I use...
5
9178
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 a datagrid do >> not << constitute a set of 'selected' records. Apparently one and only one row may be 'selected' in a datagrid. By selected row I mean the row
0
1673
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 apear in the DataGrid but still no response from the form. If I add the same data to a rich text box and don't use the datagrid I don't have this problem. What am I missing? It has to be something simple. Here is my code snipet: private...
3
5045
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, then put this control on a form. I use DataAdaptor to fill the data table and update database.
0
1334
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 able to do it in two dataGrid. ( one datagrid containing a datagrid in each row ) But I was not able to do it in three dataGrid.
4
3496
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 snippet from my .css file: *************************** body { margin:0; padding:0;
4
7375
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 close the form via a button on the toolbar (with going to another cell in the datagrid)I want to be able to popup a messagebox to the user asking them if they want to keep their changes. At the momment I'm accomplishing this by a property that...
7
5689
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 database. So all the even rows would be from database one. All the odd rows would be from database two. Row one and two will have different formats and colors.
9
2729
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 code: <script runat="server"> Dim sqlConn As New SqlConnection(".....") Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) If Not (Page.IsPostBack) Then FillDataGrid()
8
3087
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 reflect the values they anticipate committing to see hypothetical totals of columns from a set of records. These records are displaying properly on my DataGrid but I'm not sure how to get Crystal Reports 10 to use as its datasource the dataset...
0
9592
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10230
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10058
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10004
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6678
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5450
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3972
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.