How do I place controls "inside" a table cell?

How do I place controls "inside" a table cell?

Post by James » Fri, 14 Mar 2003 04:40:40



I have a TableCell in a Table (both are "runat=server"). My program
dynamically generates ASP:Button controls and puts them inside the
HtmlTableCell. The Buttons are put at absolute positions using the
"position: absolute; top: 10px; left: 20px" style properties (of couse,
the top and left values are different for each different button). Inside
my table cell, I use GridLayout instead of FlowLayout (default). Here's
is a simple skeletion of my code:

<table id=table runat=server>
<tr id=row runat=server>
<td id=cell runat=server ms_position=GridLayout></td>
</tr>
</table>

There is a function in my C# code that creates the buttons,
automatically calculates the top and left positions of each button and
then add the button to the table cell. My code for adding looks
something like this:

Button b = new Button();
b.Style.Add("position", "absolute");
b.Style.Add("top", yValue.ToString());
b.Style.Add("left", xValue.ToString());
FindControl("Main").FindControl("table").FindControl("row").FindControl(
"cell").Controls.Add(b);

So far, everything works well. However, if a Button is placed so that
some parts of it is outside the bounds of the TableCell, it just sticks
outside of the cell. I want that cell to automatically increase or
decrease in width to fit the button. Also, if the cell size reachs a
certain length (which I can specify), either the Button should be
clipped, or there should be scrollbars inside the cell that will allow
me to scroll over to see the whole button. I cannot find a way to do
this.

My explanation may be confusing, but if you follow these steps, you will
see what I am taking about:
1) In the Forms Designer, drag in an HtmlTable control
2) Create a row and a cell for that table
3) Make the width of the cell be 50 px.
4) In the HTML code, add "ms_positioning=GridLayout" to the <td> tag.
(In your Designer, you should now see the "grid dots" inside that cell)
5) Now, drag a Button web server control into that cell.
6) Place the Button so that half of it is outside the boundaries of the
cell.
7) Run your program.

You will notice that the Button appears "on top" of your table, and not
inside that cell. How come?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

 
 
 

How do I place controls "inside" a table cell?

Post by Kevin Spence » Fri, 14 Mar 2003 05:49:19


If you're putting a button inside a table cell, there is no need to use
Absolute Positioning. Just add the button to the Cell's Controls Collection.
If you need to, you can use the properties of the cell to align the button.
But adding it to the Cell's Controls Collection puts it inside the Cell
without ANY positioning.

HTH,

Kevin Spencer
Microsoft FrontPage MVP
Internet Developer
http://www.takempis.com
Different Strangs fer Different Thangs.


Quote:> I have a TableCell in a Table (both are "runat=server"). My program
> dynamically generates ASP:Button controls and puts them inside the
> HtmlTableCell. The Buttons are put at absolute positions using the
> "position: absolute; top: 10px; left: 20px" style properties (of couse,
> the top and left values are different for each different button). Inside
> my table cell, I use GridLayout instead of FlowLayout (default). Here's
> is a simple skeletion of my code:

> <table id=table runat=server>
> <tr id=row runat=server>
> <td id=cell runat=server ms_position=GridLayout></td>
> </tr>
> </table>

> There is a function in my C# code that creates the buttons,
> automatically calculates the top and left positions of each button and
> then add the button to the table cell. My code for adding looks
> something like this:

> Button b = new Button();
> b.Style.Add("position", "absolute");
> b.Style.Add("top", yValue.ToString());
> b.Style.Add("left", xValue.ToString());
> FindControl("Main").FindControl("table").FindControl("row").FindControl(
> "cell").Controls.Add(b);

> So far, everything works well. However, if a Button is placed so that
> some parts of it is outside the bounds of the TableCell, it just sticks
> outside of the cell. I want that cell to automatically increase or
> decrease in width to fit the button. Also, if the cell size reachs a
> certain length (which I can specify), either the Button should be
> clipped, or there should be scrollbars inside the cell that will allow
> me to scroll over to see the whole button. I cannot find a way to do
> this.

> My explanation may be confusing, but if you follow these steps, you will
> see what I am taking about:
> 1) In the Forms Designer, drag in an HtmlTable control
> 2) Create a row and a cell for that table
> 3) Make the width of the cell be 50 px.
> 4) In the HTML code, add "ms_positioning=GridLayout" to the <td> tag.
> (In your Designer, you should now see the "grid dots" inside that cell)
> 5) Now, drag a Button web server control into that cell.
> 6) Place the Button so that half of it is outside the boundaries of the
> cell.
> 7) Run your program.

> You will notice that the Button appears "on top" of your table, and not
> inside that cell. How come?

> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!


 
 
 

How do I place controls "inside" a table cell?

Post by James » Fri, 14 Mar 2003 06:30:50


Kevin,

You mentioned that I can use the cell's properties to align my buttons
in the cell.  However, the reason I am creating these buttons
dynamically is because I need to position them in a hierachy tree
structure (just like the folders and files in Windows Explorer).  How
can I specify each button's position with the cell's properties?  I
would think that the cell's properties would affect ALL controls that it
contains (ie. ALL buttons would be either left-aligned, right-aligned,
top-aligned, centered, etc).

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

 
 
 

How do I place controls "inside" a table cell?

Post by Kevin Spence » Fri, 14 Mar 2003 06:46:56


I didn't realize that you wanted to position multiple buttons inside a
single cell. That could be done using relative positioning, instead of
absolute.

HTH,

Kevin Spencer
Microsoft FrontPage MVP
Internet Developer
http://www.takempis.com
Different Strangs fer Different Thangs.


Quote:> Kevin,

> You mentioned that I can use the cell's properties to align my buttons
> in the cell.  However, the reason I am creating these buttons
> dynamically is because I need to position them in a hierachy tree
> structure (just like the folders and files in Windows Explorer).  How
> can I specify each button's position with the cell's properties?  I
> would think that the cell's properties would affect ALL controls that it
> contains (ie. ALL buttons would be either left-aligned, right-aligned,
> top-aligned, centered, etc).

> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!

 
 
 

1. How do I place controls "inside" a table cell

I have a TableCell in a Table (both are "runat=server"). My program
dynamically generates ASP:Button controls and puts them inside the
HtmlTableCell. The Buttons are put at absolute positions using the
"position: absolute; top: 10px; left: 20px" style properties (of couse,
the top and left values are different for each different button). Inside
my table cell, I use GridLayout instead of FlowLayout (default). Here's
is a simple skeletion of my code:

<table id=table runat=server>
<tr id=row runat=server>
<td id=cell runat=server ms_position=GridLayout></td>
</tr>
</table>

There is a function in my C# code that creates the buttons,
automatically calculates the top and left positions of each button and
then add the button to the table cell. My code for adding looks
something like this:

Button b = new Button();
b.Style.Add("position", "absolute");
b.Style.Add("top", yValue.ToString());
b.Style.Add("left", xValue.ToString());
FindControl("Main").FindControl("table").FindControl("row").FindControl(
"cell").Controls.Add(b);

So far, everything works well. However, if a Button is placed so that
some parts of it is outside the bounds of the TableCell, it just sticks
outside of the cell. I want that cell to automatically increase or
decrease in width to fit the button. Also, if the cell size reachs a
certain length (which I can specify), either the Button should be
clipped, or there should be scrollbars inside the cell that will allow
me to scroll over to see the whole button. I cannot find a way to do
this.

My explanation may be confusing, but if you follow these steps, you will
see what I am taking about:
1) In the Forms Designer, drag in an HtmlTable control
2) Create a row and a cell for that table
3) Make the width of the cell be 50 px.
4) In the HTML code, add "ms_positioning=GridLayout" to the <td> tag.
(In your Designer, you should now see the "grid dots" inside that cell)
5) Now, drag a Button web server control into that cell.
6) Place the Button so that half of it is outside the boundaries of the
cell.
7) Run your program.

You will notice that the Button appears "on top" of your table, and not
inside that cell. How come?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

2. Computer BlowOut!

3. """"""""""""""""""""""

4. Set BackColor of a Toolbar

5. "in 24 hours" - events for controls inside asp:table not available?

6. Help! OS/2 is trying to blow up my monitor!

7. Best profile for closure""""""""""Windows Server Engineer""""""""" @ Sacramento CA for 1year project

8. """"""""""Oracle Portal Developer Position"""""""" @ Dallas TX for 6+ months

9. no control generating <A HREF="" target="" onclick=""

10. Help with "this.Controls.Clear();" preceding "this.Controls.Add( newFolder );".

11. "Quote Values Differently inside a '<% "Value" %>' block

12. Any available "grid-like" control in .NET that allow string wrapping in cells???