473,378 Members | 1,152 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,378 software developers and data experts.

Forced Column Widths in a DataGrid?

Hi. Is there any way to lock down the width of columns in a DataGrid so that
even if the text in one of the rows of that column is very wide, it just gets
cut off or something rather than causing the column to get wider?

The problem is that even if I set the column to wrap text, sometimes a
single "word" or string is very long without any spaces and therefore doesn't
wrap but just forces the column wider - and that's not what I want.

Any ideas?

PS: I've tried to go the the DataGrid managed group a bunch of times over
the past month and, at least on the MSDN web site, it always shows as empty
with no items. That's why I'm posting this here instead of there.

Thanks!

Alex
Jun 16 '06 #1
3 1947
Yes, you can using something like the following in your control:

<Columns>
<asp:BoundField HeaderText="My Header" DataField="MyField"
HeaderStyle-Width="90px" />
</Columns>

That should force the column to be the width that you desire - by using
a unit measure of "px"... you can also use % to make it adjust to a
percentage of the window width...

Jun 16 '06 #2
if you read CSS documentation, you will see you can set the overflow
behavior, which is what you want to do.

-- bruce (sqlwork.com)

"Alex Maghen" <Al********@newsgroup.nospam> wrote in message
news:C2**********************************@microsof t.com...
Hi. Is there any way to lock down the width of columns in a DataGrid so
that
even if the text in one of the rows of that column is very wide, it just
gets
cut off or something rather than causing the column to get wider?

The problem is that even if I set the column to wrap text, sometimes a
single "word" or string is very long without any spaces and therefore
doesn't
wrap but just forces the column wider - and that's not what I want.

Any ideas?

PS: I've tried to go the the DataGrid managed group a bunch of times over
the past month and, at least on the MSDN web site, it always shows as
empty
with no items. That's why I'm posting this here instead of there.

Thanks!

Alex

Jun 16 '06 #3
Hi Alex,

Thank you for your post.

You may need to set the table-layout to 'fixed' to make sure fixed width
column working. For example:

protected void Page_Load(object sender, EventArgs e)
{
ArrayList ar = new ArrayList();
ar.Add("ReallylonglinewithNoSpacesAtAll!!!!!!!!!! and
anotherverylonglinelonglinelongline");
grid1.DataSource = ar;
grid1.DataBind();
grid1.Style.Add("table-layout", "fixed");
}

protected void grid1_ItemDataBound(object sender, DataGridItemEventArgs
e)
{
//e.Item.Cells[0].Text = "<nobr>" + e.Item.Cells[0].Text +
"</nobr>";
e.Item.Cells[0].Attributes.Add("WIDTH", "75px");
e.Item.Cells[0].Attributes.Add("onmouseover",
"this.title=this.innerText;");
}

This will show a table cell that has 3 lines but the two long words gets
clipped. If you don't want it gets wrapped, uncomment the first statement
in ItemDataBound and only the first word gets shown and clipped.
Regards,
Walter Wang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 20 '06 #4

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

Similar topics

3
by: Shravan Kumar | last post by:
Hi, I am using my code to set column widths of datagrid columns dynamically, but when I am setting the column widths to zero, the header text of the column whose width is made to zero is...
3
by: bismarkjoe | last post by:
Hello, I am trying to set the widths on the columns of a DataGrid component, and I'm not sure if I'm doing it correctly. My code is below: //load some inital data table = db.GetDataTable(...
3
by: sck10 | last post by:
Hello, I am using a datagrid and am trying to control the column widths for each column. Is this possible? I have tried using the following: ControlStyle-BorderWidth="1000" with no apparent...
3
by: Mike Fellows | last post by:
Im trying to set the column width of individual datgrid columns I can set the column widths of all the columns at once using Me.DataGrid1.PreferredColumnWidth = 100 But I am unable to set the...
3
by: Brian Mitchell | last post by:
I hate to ask this question because I'm sure it's been asked before, but how do you automatically resize the columns in a datagrid when the form is resized? Thanks!!
6
by: cr113 | last post by:
I'm trying to set the column widths for a datagrid. You'd think it would be easy. I looked it up in google and the first thing I found looked promising: datagrid1.columns(0).width = 2000...
1
by: kpg | last post by:
Hi All, me again. I've got my web form data grid set up pretty nice. But how do you set the column width? The columns seem to grow and shrink based on the width of the data in them (that's ok)...
4
by: Rich | last post by:
Hello, I have a one datagrid that will be based on different datatables. One datatable may have 7 columns, another 15... With the tables that have more columns, I have been manually dragging...
5
by: vpravin | last post by:
Hi guys...i am a super noob with html and aspx.. i didnt start this project but i am modifying it... q: how do i change the width of a column: Thats the table which is within a text box ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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

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.