Discussion:
Width Problem with Dynamically Created Repeater Row
Brady Kelly
2007-04-28 14:58:46 UTC
Permalink
I have an HTML table construct where I dynamically create each row (tr) for
a Repeater in the ItemDataBound event. My problem is that with some data
sources, with many columns, my resulting HTML table is too wide. In my
ItemDataBound event I iterate my column definitions and create one
HtmlTableCell for each column, and it's here I would like to set the width
of that column to something narrow than what it defaults to. However,
setting width on the HtmlTableCell has no apparent effect. How should I go
about this?



private void rptUsers_ItemDataBound(object sender,
RepeaterItemEventArgs e)

{

HtmlTableRow gridRow = new HtmlTableRow();

TaskType dataRow = e.Item.DataItem as TaskType;



gridRow = taskTypeGrid.BuildHtmlTableRow(dataRow);

((Repeater)sender).Controls.Add(gridRow);

}



public HtmlTableRow BuildHtmlTableRow(EntityBase dataRow)

{

HtmlTableRow gridRow = new HtmlTableRow();

foreach (GridColumnBase col in columns)

{

HtmlTableCell gridCell = new HtmlTableCell();

object dataValue = dataRow[col.BoundField];



gridCell.Width = "50px";

gridCell = col.BuildHtmlTableCell(dataValue);

gridRow.Controls.Add(gridCell);

}

return gridRow;

}


===================================
This list is hosted by DevelopMentor� http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Brad Wilson
2007-04-28 18:07:29 UTC
Permalink
HTML tables don't support columns with varying width row cells in them.

You have a couple choices:

1. Each row is a table unto itself (things stop lining up)
2. Don't use tables at all; use explicit positions/size and/or floating.
Post by Brady Kelly
I have an HTML table construct where I dynamically create each row (tr) for
a Repeater in the ItemDataBound event. My problem is that with some data
sources, with many columns, my resulting HTML table is too wide. In my
ItemDataBound event I iterate my column definitions and create one
HtmlTableCell for each column, and it's here I would like to set the width
of that column to something narrow than what it defaults to. However,
setting width on the HtmlTableCell has no apparent effect. How should I go
about this?
private void rptUsers_ItemDataBound(object sender,
RepeaterItemEventArgs e)
{
HtmlTableRow gridRow = new HtmlTableRow();
TaskType dataRow = e.Item.DataItem as TaskType;
gridRow = taskTypeGrid.BuildHtmlTableRow(dataRow);
((Repeater)sender).Controls.Add(gridRow);
}
public HtmlTableRow BuildHtmlTableRow(EntityBase dataRow)
{
HtmlTableRow gridRow = new HtmlTableRow();
foreach (GridColumnBase col in columns)
{
HtmlTableCell gridCell = new HtmlTableCell();
object dataValue = dataRow[col.BoundField];
gridCell.Width = "50px";
gridCell = col.BuildHtmlTableCell(dataValue);
gridRow.Controls.Add(gridCell);
}
return gridRow;
}
===================================
This list is hosted by DevelopMentor(r) http://www.develop.com
View archives and manage your subscription(s) at
http://discuss.develop.com
--
http://www.agileprogrammer.com/dotnetguy/
http://www.flickr.com/photos/dotnetguy/

===================================
This list is hosted by DevelopMentor� http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Brady Kelly
2007-04-28 18:12:19 UTC
Permalink
The columns don't have to vary in width. A column will have the same width in every row, so I thought setting the width for a column in the <thead> might set the width for all columns, but still not.
-----Original Message-----
From: Discussion of building .NET applications targeted for the Web
Sent: 28 April 2007 20:07 PM
Subject: Re: [DOTNET-WEB] Width Problem with Dynamically Created
Repeater Row
HTML tables don't support columns with varying width row cells in them.
1. Each row is a table unto itself (things stop lining up)
2. Don't use tables at all; use explicit positions/size and/or floating.
Post by Brady Kelly
I have an HTML table construct where I dynamically create each row
(tr)
Post by Brady Kelly
for
a Repeater in the ItemDataBound event. My problem is that with some
data
Post by Brady Kelly
sources, with many columns, my resulting HTML table is too wide. In
my
Post by Brady Kelly
ItemDataBound event I iterate my column definitions and create one
HtmlTableCell for each column, and it's here I would like to set the
width
Post by Brady Kelly
of that column to something narrow than what it defaults to. However,
setting width on the HtmlTableCell has no apparent effect. How should
I
Post by Brady Kelly
go
about this?
private void rptUsers_ItemDataBound(object sender,
RepeaterItemEventArgs e)
{
HtmlTableRow gridRow = new HtmlTableRow();
TaskType dataRow = e.Item.DataItem as TaskType;
gridRow = taskTypeGrid.BuildHtmlTableRow(dataRow);
((Repeater)sender).Controls.Add(gridRow);
}
public HtmlTableRow BuildHtmlTableRow(EntityBase dataRow)
{
HtmlTableRow gridRow = new HtmlTableRow();
foreach (GridColumnBase col in columns)
{
HtmlTableCell gridCell = new HtmlTableCell();
object dataValue = dataRow[col.BoundField];
gridCell.Width = "50px";
gridCell = col.BuildHtmlTableCell(dataValue);
gridRow.Controls.Add(gridCell);
}
return gridRow;
}
===================================
This list is hosted by DevelopMentor(r) http://www.develop.com
View archives and manage your subscription(s) at
http://discuss.develop.com
--
http://www.agileprogrammer.com/dotnetguy/
http://www.flickr.com/photos/dotnetguy/
===================================
This list is hosted by DevelopMentor http://www.develop.com
View archives and manage your subscription(s) at
http://discuss.develop.com
===================================
This list is hosted by DevelopMentor� http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
John Warner
2007-04-29 12:07:19 UTC
Permalink
Have you considered looking at your data as it is returned from your
query and provide your own <br /> tags on long lines? You'd have to do
the lifting yourself instead of databinding but you are then fully in
control of column widths.

John Warner
Date: Sat, 28 Apr 2007 16:58:46 +0200
Subject: Width Problem with Dynamically Created Repeater Row
I have an HTML table construct where I dynamically create
each row (tr) for a Repeater in the ItemDataBound event. My
problem is that with some data sources, with many columns, my
resulting HTML table is too wide. In my ItemDataBound event
I iterate my column definitions and create one HtmlTableCell
for each column, and it's here I would like to set the width
of that column to something narrow than what it defaults to.
However, setting width on the HtmlTableCell has no apparent
effect. How should I go about this?
private void rptUsers_ItemDataBound(object sender,
RepeaterItemEventArgs e)
{
HtmlTableRow gridRow = new HtmlTableRow();
TaskType dataRow = e.Item.DataItem as TaskType;
gridRow = taskTypeGrid.BuildHtmlTableRow(dataRow);
((Repeater)sender).Controls.Add(gridRow);
}
public HtmlTableRow BuildHtmlTableRow(EntityBase dataRow)
{
HtmlTableRow gridRow = new HtmlTableRow();
foreach (GridColumnBase col in columns)
{
HtmlTableCell gridCell = new HtmlTableCell();
object dataValue = dataRow[col.BoundField];
gridCell.Width = "50px";
gridCell = col.BuildHtmlTableCell(dataValue);
gridRow.Controls.Add(gridCell);
}
return gridRow;
}
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.467 / Virus Database: 269.6.2/779 - Release Date: 4/28/2007
3:32 PM

===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Brady Kelly
2007-04-29 12:34:20 UTC
Permalink
I'm using the table as an editable grid, and the problem with wide data
arises when I add a 'select' element to my table row. The select auto-sizes
to the longest entry in its data source, and I want to prevent this.
-----Original Message-----
From: Discussion of building .NET applications targeted for the Web
Sent: 29 April 2007 14:07 PM
Subject: Re: [DOTNET-WEB] Width Problem with Dynamically Created
Repeater Row
Have you considered looking at your data as it is returned from your
query and provide your own <br /> tags on long lines? You'd have to do
the lifting yourself instead of databinding but you are then fully in
control of column widths.
John Warner
Date: Sat, 28 Apr 2007 16:58:46 +0200
Subject: Width Problem with Dynamically Created Repeater Row
I have an HTML table construct where I dynamically create
each row (tr) for a Repeater in the ItemDataBound event. My
problem is that with some data sources, with many columns, my
resulting HTML table is too wide. In my ItemDataBound event
I iterate my column definitions and create one HtmlTableCell
for each column, and it's here I would like to set the width
of that column to something narrow than what it defaults to.
However, setting width on the HtmlTableCell has no apparent
effect. How should I go about this?
private void rptUsers_ItemDataBound(object sender,
RepeaterItemEventArgs e)
{
HtmlTableRow gridRow = new HtmlTableRow();
TaskType dataRow = e.Item.DataItem as TaskType;
gridRow = taskTypeGrid.BuildHtmlTableRow(dataRow);
((Repeater)sender).Controls.Add(gridRow);
}
public HtmlTableRow BuildHtmlTableRow(EntityBase dataRow)
{
HtmlTableRow gridRow = new HtmlTableRow();
foreach (GridColumnBase col in columns)
{
HtmlTableCell gridCell = new HtmlTableCell();
object dataValue = dataRow[col.BoundField];
gridCell.Width = "50px";
gridCell = col.BuildHtmlTableCell(dataValue);
gridRow.Controls.Add(gridCell);
}
return gridRow;
}
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.467 / Virus Database: 269.6.2/779 - Release Date: 4/28/2007
3:32 PM
===================================
This list is hosted by DevelopMentorR http://www.develop.com
View archives and manage your subscription(s) at
http://discuss.develop.com
===================================
This list is hosted by DevelopMentor� http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Loading...