473,687 Members | 3,770 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

calculating the height of a dynamically generated table

I am created a table dynamically and I have wrapped it in a div tag so that
the user can scroll the table horizontally ie I have added an overflow
property to the div. I dont want the user to be able to scroll vertically so
I need to set the height of the div at runtime based on the number of table
rows generated. Ideally I want the div scrollbars to sit just underneath the
bottom of the table.

I have looked around and haven't found anything to enable me to do this.
Has anybody got any ideas?

Thanks in advance.
Jul 21 '05 #1
3 2321
If you create the table dynamically, you can set the row's height when you
generate them (use the Height property of the TableRow class). Once you do
that, when youre done adding rows, multiply the number of rows times the
height. That gives you a good estimate on what the total table height is
(not counting Cellpadding or Spacing).

if you created the DIV dynamically (or specify runat server), you can set
the DIV height to the total table height (plus a little more).

I'm going ot see if I can make this work.
"rufus" <ru***@discussi ons.microsoft.c om> wrote in message
news:1C******** *************** ***********@mic rosoft.com...
I am created a table dynamically and I have wrapped it in a div tag so that the user can scroll the table horizontally ie I have added an overflow
property to the div. I dont want the user to be able to scroll vertically so I need to set the height of the div at runtime based on the number of table rows generated. Ideally I want the div scrollbars to sit just underneath the bottom of the table.

I have looked around and haven't found anything to enable me to do this.
Has anybody got any ideas?

Thanks in advance.

Jul 21 '05 #2
See if this helps. Change the array size and uncomment the other elements to
see the changes in height. The ExtraPadding variable should accomodate for
padding, but you will probably want to mess with it yourself.

Private RowHeight As Integer = 20

Private ExtraPadding As Integer = 20

Private Sub Page_PreRender( ByVal sender As Object, ByVal e As
System.EventArg s) Handles MyBase.PreRende r

Dim testArray(7) As String

testArray(0) = "item 1"

testArray(1) = "item 2"

testArray(2) = "item 3"

testArray(3) = "item 4"

testArray(4) = "item 5"

testArray(5) = "item 6"

testArray(6) = "item 7"

'testArray(7) = "item 8"

'testArray(8) = "item 9"

'testArray(9) = "item 10"

For Each strItem As String In testArray

Dim Row As New TableRow

Row.Height = Unit.Pixel(RowH eight)

Dim Cell As New TableCell

Cell.Text = strItem

Row.Cells.Add(C ell)

Me.DynamicTable .Rows.Add(Row)

Next

DynamicTable.Wi dth = Unit.Pixel(350)

Dim DivHeight As Integer = (RowHeight * Me.DynamicTable .Rows.Count) +
ExtraPadding

Dim DivTag As New HtmlGenericCont rol("DIV")

DivTag.Attribut es.Add("STYLE", "Height:" & Unit.Pixel(DivH eight).ToString &
"; BACKGROUND-COLOR:gainsboro ; WIDTH:200px;OVE RFLOW:auto")

DivTag.Controls .Add(DynamicTab le)

Page.FindContro l("Form1").Cont rols.Add(DivTag )

End Sub

"Elliot Rodriguez" <el************ **@hotmail.com> wrote in message
news:ef******** ******@TK2MSFTN GP10.phx.gbl...
If you create the table dynamically, you can set the row's height when you
generate them (use the Height property of the TableRow class). Once you do
that, when youre done adding rows, multiply the number of rows times the
height. That gives you a good estimate on what the total table height is
(not counting Cellpadding or Spacing).

if you created the DIV dynamically (or specify runat server), you can set
the DIV height to the total table height (plus a little more).

I'm going ot see if I can make this work.
"rufus" <ru***@discussi ons.microsoft.c om> wrote in message
news:1C******** *************** ***********@mic rosoft.com...
I am created a table dynamically and I have wrapped it in a div tag so that
the user can scroll the table horizontally ie I have added an overflow
property to the div. I dont want the user to be able to scroll

vertically so
I need to set the height of the div at runtime based on the number of table
rows generated. Ideally I want the div scrollbars to sit just

underneath the
bottom of the table.

I have looked around and haven't found anything to enable me to do this.
Has anybody got any ideas?

Thanks in advance.


Jul 21 '05 #3
Thanks Elliot,

Your code really helped. Exactly what I was looking for.

"Elliot Rodriguez" wrote:
See if this helps. Change the array size and uncomment the other elements to
see the changes in height. The ExtraPadding variable should accomodate for
padding, but you will probably want to mess with it yourself.

Private RowHeight As Integer = 20

Private ExtraPadding As Integer = 20

Private Sub Page_PreRender( ByVal sender As Object, ByVal e As
System.EventArg s) Handles MyBase.PreRende r

Dim testArray(7) As String

testArray(0) = "item 1"

testArray(1) = "item 2"

testArray(2) = "item 3"

testArray(3) = "item 4"

testArray(4) = "item 5"

testArray(5) = "item 6"

testArray(6) = "item 7"

'testArray(7) = "item 8"

'testArray(8) = "item 9"

'testArray(9) = "item 10"

For Each strItem As String In testArray

Dim Row As New TableRow

Row.Height = Unit.Pixel(RowH eight)

Dim Cell As New TableCell

Cell.Text = strItem

Row.Cells.Add(C ell)

Me.DynamicTable .Rows.Add(Row)

Next

DynamicTable.Wi dth = Unit.Pixel(350)

Dim DivHeight As Integer = (RowHeight * Me.DynamicTable .Rows.Count) +
ExtraPadding

Dim DivTag As New HtmlGenericCont rol("DIV")

DivTag.Attribut es.Add("STYLE", "Height:" & Unit.Pixel(DivH eight).ToString &
"; BACKGROUND-COLOR:gainsboro ; WIDTH:200px;OVE RFLOW:auto")

DivTag.Controls .Add(DynamicTab le)

Page.FindContro l("Form1").Cont rols.Add(DivTag )

End Sub

"Elliot Rodriguez" <el************ **@hotmail.com> wrote in message
news:ef******** ******@TK2MSFTN GP10.phx.gbl...
If you create the table dynamically, you can set the row's height when you
generate them (use the Height property of the TableRow class). Once you do
that, when youre done adding rows, multiply the number of rows times the
height. That gives you a good estimate on what the total table height is
(not counting Cellpadding or Spacing).

if you created the DIV dynamically (or specify runat server), you can set
the DIV height to the total table height (plus a little more).

I'm going ot see if I can make this work.
"rufus" <ru***@discussi ons.microsoft.c om> wrote in message
news:1C******** *************** ***********@mic rosoft.com...
I am created a table dynamically and I have wrapped it in a div tag so

that
the user can scroll the table horizontally ie I have added an overflow
property to the div. I dont want the user to be able to scroll

vertically
so
I need to set the height of the div at runtime based on the number of

table
rows generated. Ideally I want the div scrollbars to sit just

underneath
the
bottom of the table.

I have looked around and haven't found anything to enable me to do this.
Has anybody got any ideas?

Thanks in advance.



Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
5176
by: kie | last post by:
hello, i have a table that creates and deletes rows dynamically using createElement, appendChild, removeChild. when i have added the required amount of rows and input my data, i would like to calculate the totals in each row. when i try however, i receive the error: "Error: 'elements' is null or not an object"
7
3071
by: Just Dummy | last post by:
Hi all, I am struggling with a problem for a long time. Problem statement: I have a table and the table can contain n number of rows. i.e., the table rows will be generataed out of a xml using a xslt. Now the problem is I want the table to be only with a height of 200px. if this exceeds beyond 200px, a vertical scroll bar along should appear. The horizontal
3
2689
by: Andrew Dodgshun | last post by:
I have 2 grids - one shows a list of table names in a database and when you click on a table name the other grid dynamically populates the grid with the table contents. My problem is that I cannot get any changes I do in the grid of a given table saved back to the database unless I nominate a particular table in the SQLDataAdapter but this is not dynamic as the table changes when the user picks another table I have the first part working...
2
6762
by: Robson Carvalho Machado | last post by:
Dear friends, I'm dynamically creating a Hyperlink with spacer.gif as ImageURL that is an 1px transparent image only to determine link position, but as I create this link dynamically I could not set image width. This problem makes my link clickable only on its borders. When viewing HTML source I could see that spacer.gif has no width and height, so HTML shows only 1px x 1 px image.
5
1871
by: Kat | last post by:
Hi, I'm trying to set up an asp.net page using flow layout so I'm putting all my controls into a table grid, etc. I use several radiobuttonlists and datagrids that are generated from datasource. The radiobuttonlists are fine, they size depending on how many item are called into it. However, the datagrids, prior to filling with data contain FIVE "Databound" items and the grid does not shrink if it is filled with only 2 for example....
3
1493
by: RJN | last post by:
Hi I need to find the datagrid height dynamically based on the no. of records in the grid. I have set the height for the Item style and alternating item style. But I can not depend on this since some of the records might get wrapped and hence I need to find this dynamically. Based on the grid height, I need to align another table in my page. Is there a way to do this? Thanks
2
2717
by: Steve Bottoms | last post by:
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 (table.height.value) to be able to dynamically position the next elements on the form. However, this control property is coming back as -0- every time. I also try to get the table height with Javascript after-the-fact (table.style.height), but that...
3
522
by: rufus | last post by:
I am created a table dynamically and I have wrapped it in a div tag so that the user can scroll the table horizontally ie I have added an overflow property to the div. I dont want the user to be able to scroll vertically so I need to set the height of the div at runtime based on the number of table rows generated. Ideally I want the div scrollbars to sit just underneath the bottom of the table. I have looked around and haven't found...
3
5815
by: Peter | last post by:
I have a datalist and I want the datalist to grow from no records to fill the screen, but not go beyond the screen height. How do I do that? I've implemented the scroll bars but it works only for the fixed height. I want the datalist to grow and shrink and never go beyond the current screen height, if the data can not fit in one screen I want to implement scroll bars, but only scroll the datalist not any other parts. Thank You
0
8590
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8524
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9066
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8779
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8783
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6449
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4540
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2212
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1946
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.