473,770 Members | 5,284 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 2329
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
5197
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
3083
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
2695
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
6770
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
1876
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
1497
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
2723
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
5820
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
10225
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...
0
10053
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10001
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,...
1
7415
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
6676
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5312
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3969
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3573
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.