Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > problem sizing columns in datagrid

Reply
Thread Tools

problem sizing columns in datagrid

 
 
Mad Scientist Jr
Guest
Posts: n/a
 
      08-13-2004
I have a datagrid that has a column that I would like to be the widest
(say 60%) - however another column is populated with some data that is
sometimes a rather long string, and it expands to take up most of the
table width. I tried to force the column sizes to force the longer
column to wrap but it isn't working. Any help appreciated, my code is
below:

DataGrid1.DataSource = DataTable1
DataGrid1.DataBind()
DataGrid1.Columns(0).ItemStyle.Width = Unit.Percentage(10)
DataGrid1.Columns(1).ItemStyle.Width = Unit.Percentage(60)
' this column is getting squashed
DataGrid1.Columns(2).ItemStyle.Width = Unit.Percentage(10)
' this column still ends up taking 70% or so
DataGrid1.Columns(3).ItemStyle.Width = Unit.Percentage(10)
 
Reply With Quote
 
 
 
 
anon
Guest
Posts: n/a
 
      08-18-2004

One solution is to check the length of this particular column that is
causing wider columns in itemdatabound....

string d = Convert.ToString(DataBinder.Eval(e.Item.DataItem,. ...));
if (d.Length > 50)
{
Label lb = (Label) e.Item.FindControl("lb");
lb.Text = d.Substring(0, 45) + "...";

}

Hope that helps,
Ben

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
 
Mad Scientist Jr
Guest
Posts: n/a
 
      08-20-2004
actually that's not a bad idea... thanks for responding
 
Reply With Quote
 
Mike Hutton
Guest
Posts: n/a
 
      08-24-2004
anon <(E-Mail Removed)> wrote in message news:<#(E-Mail Removed)>...
> One solution is to check the length of this particular column that is
> causing wider columns in itemdatabound....
>
> string d = Convert.ToString(DataBinder.Eval(e.Item.DataItem,. ...));
> if (d.Length > 50)
> {
> Label lb = (Label) e.Item.FindControl("lb");
> lb.Text = d.Substring(0, 45) + "...";
>
> }
>
> Hope that helps,
> Ben


I have a related problem, but one which I can't really use substrings
on.

I have a column which has generated HTML tags in it. The tag is a link
to a javascript function which needs to be called with the key value
of the row, and also has a JPG embedded in it. I want to be able to
use this as my grid needs to be dynamic - I don't always want to
display this column.

As you can guess, the DataGrid is resizing my grid so that the column
takes up space commensurate with the size of the text which generates
the link, rather than the image it displays.

Is there any way I can completely override the column width so it
doesn't "correct" it in this way?

Mike.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
IEx Hell (again): AUTO-SIZING IMAGES in Multiple Columns w/DIV Tags &CSS MISS CHIEVOUS HTML 51 04-19-2009 04:25 PM
Tkinter and the re/sizing of columns in a grid noman@cyclops.org Python 1 11-12-2005 07:49 PM
Sizing text entry boxes on in-place editing of datagrid row with dynamically created columns Keefe Goldfisher via .NET 247 ASP .Net Datagrid Control 0 03-07-2005 07:00 PM
Binded Datagrid Formatting columns or hiding columns ton ASP .Net Web Controls 2 02-11-2004 04:09 AM
Columns and Inherited Datagrid...Active Schema does not support columns rob thomson ASP .Net Datagrid Control 0 09-04-2003 03:09 PM



Advertisments