PC Review


Reply
Thread Tools Rate Thread

calculating the height of a dynamically generated table

 
 
=?Utf-8?B?cnVmdXM=?=
Guest
Posts: n/a
 
      16th Feb 2005
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.
 
Reply With Quote
 
 
 
 
Elliot Rodriguez
Guest
Posts: n/a
 
      16th Feb 2005
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" <(E-Mail Removed)> wrote in message
news:1CFAB9FF-F341-4141-910E-(E-Mail Removed)...
> 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.



 
Reply With Quote
 
Elliot Rodriguez
Guest
Posts: n/a
 
      16th Feb 2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:1CFAB9FF-F341-4141-910E-(E-Mail Removed)...
> > 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.

>
>



 
Reply With Quote
 
=?Utf-8?B?cnVmdXM=?=
Guest
Posts: n/a
 
      17th Feb 2005
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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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" <(E-Mail Removed)> wrote in message
> > news:1CFAB9FF-F341-4141-910E-(E-Mail Removed)...
> > > 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.

> >
> >

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
I need to change table height dynamically through C#/VB lwoods Microsoft ASP .NET 1 14th May 2006 04:42 PM
How to export dynamically generated html table to Excel Sheet =?Utf-8?B?U21pdGhhIEJhdmFuZGxh?= Microsoft Access External Data 0 11th Aug 2005 02:31 PM
SPAN around dynamically generated TABLE ROW?? Jack Black Microsoft ASP .NET 1 13th Apr 2005 05:41 PM
Viewstate of Dynamically Generated Table Rowss ?? =?Utf-8?B?RGF2aWQgSm9uZXM=?= Microsoft ASP .NET 2 7th Feb 2005 06:51 AM
Dynamically generated Table Rows Dissappear Bijoy Naick Microsoft ASP .NET 3 30th Nov 2004 12:46 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:50 AM.