473,396 Members | 1,968 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.

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 2298
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***@discussions.microsoft.com> wrote in message
news:1C**********************************@microsof t.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.EventArgs) Handles MyBase.PreRender

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(RowHeight)

Dim Cell As New TableCell

Cell.Text = strItem

Row.Cells.Add(Cell)

Me.DynamicTable.Rows.Add(Row)

Next

DynamicTable.Width = Unit.Pixel(350)

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

Dim DivTag As New HtmlGenericControl("DIV")

DivTag.Attributes.Add("STYLE", "Height:" & Unit.Pixel(DivHeight).ToString &
"; BACKGROUND-COLOR:gainsboro; WIDTH:200px;OVERFLOW:auto")

DivTag.Controls.Add(DynamicTable)

Page.FindControl("Form1").Controls.Add(DivTag)

End Sub

"Elliot Rodriguez" <el**************@hotmail.com> wrote in message
news:ef**************@TK2MSFTNGP10.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***@discussions.microsoft.com> wrote in message
news:1C**********************************@microsof t.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.EventArgs) Handles MyBase.PreRender

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(RowHeight)

Dim Cell As New TableCell

Cell.Text = strItem

Row.Cells.Add(Cell)

Me.DynamicTable.Rows.Add(Row)

Next

DynamicTable.Width = Unit.Pixel(350)

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

Dim DivTag As New HtmlGenericControl("DIV")

DivTag.Attributes.Add("STYLE", "Height:" & Unit.Pixel(DivHeight).ToString &
"; BACKGROUND-COLOR:gainsboro; WIDTH:200px;OVERFLOW:auto")

DivTag.Controls.Add(DynamicTable)

Page.FindControl("Form1").Controls.Add(DivTag)

End Sub

"Elliot Rodriguez" <el**************@hotmail.com> wrote in message
news:ef**************@TK2MSFTNGP10.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***@discussions.microsoft.com> wrote in message
news:1C**********************************@microsof t.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
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...
7
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...
3
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...
2
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...
5
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....
3
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...
2
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...
3
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...
3
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
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...
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
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...
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.