473,396 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

determining height of a dynamic table after it has been loaded & populated with data

2
Hi, all! Using VB as code-behind in asp.net page...

I have a TABLE control which I'm building dynamically. After the table is
built, I'm trying to retrieve the HEIGHT property of that table
to be able to dynamically position the next elements on
the form. However, this control property is coming back as blank every time.

How can I get the height of the TABLE control AFTER building it, so I know
where to place the next few elements in the flow???
Apr 4 '10 #1
2 4776
tlhintoq
3,525 Expert 2GB
This may not apply at all but...

I've seen several controls in Windows.Forms applications that don't have any size or bounds information until they are shown. It seems like these properties don't get filled in until they have a parent window handle, and have had things such as O.S. visual styles applied. I guess it makes sense: How can you know the width until you know if the border has a width of 1 or 5, depending on the visual style?
Apr 4 '10 #2
Frinavale
9,735 Expert Mod 8TB
HTML is made up of elements and it doesn't care about how these elements are styled. They are in the page where they are in the page. If you need something before the table then you place the element before the table...if you need something after the table then you place things after the table.

The flow of the page (when it is rendered) may be modified using the element's style property. You can either set the individual style properties or you can set the style "class" that the element should use. The classes etc can be defined in Cascading Style Sheets.

Now that that's clarified, if you want to know the height of the table you can do so using JavaScript. Once you get a reference to the HTML element in your JavaScript code you can access that element's offsetHeight property (or clientHeight property depending on which browser you're using) to determine the physical height of the element as displayed in the browser. Likewise you can determine the width of the element using the offsetWidth (or clientWidht) property.

Here is an example of some JavaScript that will retrieve an HTML table element (with the ID "myTable") and display the table's physical height and width:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3.  
  4. <table id="myTable" border="1">
  5.   <tr><th>Column 1</th><th>Column 2</th><th>Column 3</th></tr>
  6.   <tr><td>1,1</td><td>1,2</td><td>1,3</td></tr>
  7.   <tr><td>2,1</td><td>2,2</td><td>2,3</td></tr>
  8.   <tr><td>3,1</td><td>3,2</td><td>3,3</td></tr>
  9.   <tr><td>4,1</td><td>4,2</td><td>4,3</td></tr>
  10.   <tr><td>5,1</td><td>5,2</td><td>5,3</td></tr>
  11.   <tr><td>6,1</td><td>6,2</td><td>6,3</td></tr>
  12.   <tr><td>7,1</td><td>7,2</td><td>7,3</td></tr>
  13.   <tr><td>8,1</td><td>8,2</td><td>8,3</td></tr>
  14. </table>
  15.  
  16. <script type="text/javascript">
  17.   var myTable = document.getElementById("myTable");
  18.   var width = myTable.offsetWidth ? myTable.offsetWidth : myTable.clientWidth;
  19.   var height= myTable.offsetHeight ? myTable.offsetHeight: myTable.clientWidth;
  20.  
  21.   var str = "myTable's height: "+height+"px     myTable's width: "+width+"px";
  22.   alert(str);
  23. </script>
  24.  
  25. </body>
  26. </html>
  27.  

Now, there's a couple of things to note here. First of all, this is not specific to tables. This code will tell you the physical height and width of any* DOM (HTML) element. So you can also use this to get the height and width of a <div> element for example. *The element must have layout (haslayout property) in order to use the offsetHeight/clientHeight and offsetWidth/clientWidth.

The other thing to note is that the element must be visible in order for this to work. So that means that if your element has a style of "display:none" the offsetHeight/clientHeight and offsetWidth/clientWidht will always be 0.


-Frinny
Apr 5 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Paul | last post by:
Hi, I'm wondering if someone out there can help me overcome this quandary. I need to be able to calculate the height of the current page. I need to calculate the height of the page in pixels after...
22
by: Les Juby | last post by:
I am trying to adjust the window/table size of a website (www.worklaw.co.za) which has made use of DIV tags with its settings embedded in an CSS file. The client wants its width and height to...
6
by: Fan Ruo Xin | last post by:
I try to copy a table from production system (DB2 UDB EEE V7.2 + fixpak5) to the testing system (DB2 UDB V8.1 + fixpak4a). I moved the data from productions system by using the following steps:...
1
by: Scott Schluer | last post by:
Hello, I've got myself a small problem and I'm hoping someone can help. I have a DataList called dlProducts (displays products from a database). Within the <ItemTemplate> container of the...
4
by: Gregory Gadow | last post by:
If there is a more appropriate forum, please let me know and I will post there. Our field reps can go on to our website and select from several sets of data to create the address we then provide...
3
by: toffee | last post by:
Hi all, Here's the situation: I have a table of data; and I would like to add a div with exactly the same height and width as the top-left header. The problem is as the data is dynamic and the...
2
by: JMT | last post by:
Hello, I get some dynamic controls (ASP .Net) inside a table, the height property of the table is variable according the controls loaded, so I need to know the final table height, this value...
9
by: pbd22 | last post by:
Hi. This is just a disaster management question. I am using XMLHTTP for the dynamic loading of content in a very crucial area of my web site. Same as an IFrame, but using XMLHTTP and a DIV. I...
0
by: Vinod Sadanandan | last post by:
Table Partition Performance analysis ============================================ Collection of Statistics for Cost-Based Optimization/DBMS_STATS vs. ANALYZE The cost-based approach relies on...
3
balabaster
by: balabaster | last post by:
I've got a user control that builds a table of dynamic data based on a :LINQ class holding the data. The data is loaded using the LoadData(DataInstance) method. The table it builds contains a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.