How retrieve width of a cell?

N

needin4mation

Please Consider this code snippet:

private void dgdHistory_ItemCreated(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem ||
e.Item.ItemType == ListItemType.EditItem)
{
TableCell myChangeCell = e.Item.Cells[0];
Button myChangeButton = (Button) myChangeCell.Controls[0];
Response.Write("myTableCell: " + myTableCell.Width + ", ");

....

The cell never reports a width. It is just blank. The Response.Write
works. I can see the "myTableCell: , ." There is just no width
reported.

Any ideas? Thanks.
 
N

needin4mation

I have also tried this:

public void dgdHistory_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem
)
TableCell myTableCell = e.Item.Cells[0];

Response.Write("cell width: " + myTableCell.Width + ", " );

nothing.
 
T

The Crow

do you want to retrive "Width" of the Cell which is calculated by the users
browser? that is not possible. but if you explicitly gave the cell a width
value in the column template in the datagrid then i think you should retrive
it.
 
N

needin4mation

Essentially, what I am trying to do is create a div with table cells
that are the correct size. This is for a scrollable datagraid (read
scrollable div). By taking the width of the cells in the datagrid, I
was hoping to make that the width of the tableheader cells in the div.
All this keeps the headers from moving when the user scrolls the div
containing the datagrid.
 
T

The Crow

did you think using repater instead of datagrid? i think it would easer to
implement. datagrid is a form of repeater, repeater itself is a customizable
for loop anyway :) implementing sorting would not be hard. implementing
paging is a bit difficult but you can find sources about this on the
internet.
 
T

The Crow

did you try

TableCell myTableCell = e.Item.Cells[0];

Response.Write("cell width: " + myTableCell.Attributes["width"] + ", " ); or
["Width"] ? and try ["Style"] or ["style"] for possible css attributes. or
output every attribute via a for loop
 
B

Bruce Barker

you will need to do this with client script, as ther server never knows what
the rendered cell with. you can fix the widths on the srever is you specify
the with in pixels, and supply a proper overflow method (default overflow
method is to widen the td).

at page load have client script set the heading widths (with overflow
control) to the table widths. if you allow horizonal scrolling you will have
some trickly code to keep them in sync.

-- bruce (sqlwork.com)
 
J

Jeremy Chapman

You must either explicitly set the width in code first, or check the width
of the cell using javascript client side. If you set the width in code to a
relative value (percentage) and you want to determine in pixels how wide it
is you'll need to do that in javascript because that's the only way to
determine how the browser has rendered the cell.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top