How can I put 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 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? -
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 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? -
Use WebControls, instead of HtmlControls, add the member as protected in your code-behind, then you dont need that FindCOntrol thing. I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
At first, I did use an ASP:Table server control. However, I found that I was unable to add any control within the Table's cells by using drag and drop. Then I created a regular HtmlTable. With this I was able to drag and drop anything into the cell. Are you having this problem?
-
At first, I did use an ASP:Table server control. However, I found that I was unable to add any control within the Table's cells by using drag and drop. Then I created a regular HtmlTable. With this I was able to drag and drop anything into the cell. Are you having this problem?
Us hardcore guys, dont use the WebFormsDesigner. Well not the drag'n drop bit, but the source. What I ussaully do is just to drop the control on the page, then switch to sourceview and "move" the textbox to the cell. I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
-
Us hardcore guys, dont use the WebFormsDesigner. Well not the drag'n drop bit, but the source. What I ussaully do is just to drop the control on the page, then switch to sourceview and "move" the textbox to the cell. I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
This is exactly what I do too. The IDE doesn't let you drop controls into a server side table, so I just drag it onto the page, set whatever properties I want, then switch to HTML view and move it into the table code where I want it to live. It's a pain, but it works.