473,394 Members | 1,951 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,394 software developers and data experts.

dynamically adding table rows and cells...

Hi all,

I'm desperately trying to get this to work and I just cant do it - new to
ASP.net - probably the reason!

I'm using visual studio for this - I have this in the html page :

<asp:Table id="Table1" runat="server"></asp:Table>

there is other code too but I believe this to be the relevant part...

In my button on click event I am trying to do this :

Dim tRow As New TableRow()
Table1.Rows.Add(tRow)

which I have copied EXACTLY from the visual studio help and MS site (both
examples the same etc)..

2 problems..

1: The brackets get removed from the first line
2: the tRow within the brackets gets underlined and has the following error
:

Value of type 'System.Web.UI.WebControls.TableRow' cannot be converted to
'System.Web.UI.HtmlControls.HtmlTableRow'.

I have no idea what the problems is or how to fix it - however I do suspect
the item 2 is a direct result of the missing brackets in item 1 - and that
these are probably missing because I've not done some form of 'IMPORT' at
the top of the page???

But to be honest I have no real clue....

If someone could suggest a reason / way forward I would be most grateful.

Regards

Rob


Nov 18 '05 #1
4 14052
Hey Rob,

Try one of the following two:

1. (In a C# code behind for the button click event)

System.Web.UI.WebControls.TableRow tr = new
System.Web.UI.WebControls.TableRow();
System.Web.UI.WebControls.TableCell tc = new
System.Web.UI.WebControls.TableCell();
tc.Text = "blah";
tr.Cells.Add(tc);
myTable.Rows.Add(tr); //This assumes you have a asp:table server control
with an id="myTable"

(In the .aspx file)

<asp:Table ID="neat" Runat="server">
<asp:TableRow>
<asp:TableCell>
slick
</asp:TableCell>
</asp:TableRow>
</asp:Table>

2.
Dim tRow As New TableRow()
Table1.Rows.Add(tRow)
Change this to use explicit declarations like I did above. It appears that
there are two different libraries with two different methods of creating
TableRows, and you HAVE to be consistent with the table type you've created.
Based on your error message, it appears that there are:

a) System.Web.UI.WebControls.TableRow
b) System.Web.UI.HtmlControls.HtmlTableRow

Hope you find this moderately useful. Good luck!

Mark
www.dovetaildatabases.com

"Rob Meade" <ro**********@NOSPAMubht.swest.nhs.uk> wrote in message
news:us**************@tk2msftngp13.phx.gbl... Hi all,

I'm desperately trying to get this to work and I just cant do it - new to
ASP.net - probably the reason!

I'm using visual studio for this - I have this in the html page :

<asp:Table id="Table1" runat="server"></asp:Table>

there is other code too but I believe this to be the relevant part...

In my button on click event I am trying to do this :

Dim tRow As New TableRow()
Table1.Rows.Add(tRow)

which I have copied EXACTLY from the visual studio help and MS site (both
examples the same etc)..

2 problems..

1: The brackets get removed from the first line
2: the tRow within the brackets gets underlined and has the following error :

Value of type 'System.Web.UI.WebControls.TableRow' cannot be converted to
'System.Web.UI.HtmlControls.HtmlTableRow'.

I have no idea what the problems is or how to fix it - however I do suspect the item 2 is a direct result of the missing brackets in item 1 - and that
these are probably missing because I've not done some form of 'IMPORT' at
the top of the page???

But to be honest I have no real clue....

If someone could suggest a reason / way forward I would be most grateful.

Regards

Rob

Nov 18 '05 #2
"Rob Meade" wrote ...

[..snip..]

Found part of the problem by the looks of it...

Having added a couple of tables previously, the Protected with crap that
gets generated automatically by VS was still there, I had then removed the
table which was wrong and added a new one, gave it the same name and it used
the first lots of protected with stuff....as soon as i changed that - no
errors or scribbly lines....

Anyone know why VS doesn't remove these lines of code that it adds on your
behalf?

Regards

Rob
Nov 18 '05 #3
> Value of type 'System.Web.UI.WebControls.TableRow' cannot be converted to
'System.Web.UI.HtmlControls.HtmlTableRow'.


Rob,
The error you are getting is because you are declaring your table row
as an HTML control then trying to add it to a WebControl.

I personally do not use the web control for tables. I simply add the
runat="server" tag to a regular HTML Table decalration.
Like this...
<Table id="Table1" runat="server"></Table>

Then, in your code behind page, make sure that you add the following

Imports System.Web.UI.HtmlControls
(above the class declaration)

and

Protected WithEvents Table1 As HtmlTable
(above the page_load sub but below the class declaration.
The key being that this is an HTMLTable not a WebControl)
Then in your code that dynamically creates the table row and cell,

Dim tRow as TableRow (Remember this is a
System.Web.UI.HtmlControls.TableRow)
Dim tCell as TableCell (System.Web.UI.HtmlControls.TableCell)

tCell.Attributes.Add("nowrap",True) 'Add any attributes you may
need
tCell.InnerHtml = "<B>Hello World</B>" 'Add HTML to the Cell

tRow.Cells.Add(tCell) 'Add the cell to the row
Table1.Rows.Add(tRow) 'Add the row to the table

Hope this helps.

Danny
Nov 18 '05 #4
"Danny Bloodworth" wrote...

[..snip..]

Many thanks for a very informative reply Danny, your help is appreciated.

Regards

Rob
Nov 18 '05 #5

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

Similar topics

4
by: Grigs | last post by:
Hello, I have an asp:table on my page. I am, after a button gets clicked, programmatically adding rows and their cells. Using the Cell.Text = to put the value in the cell. I then have another...
3
by: Bijoy Naick | last post by:
I have something strange going on.. My .aspx page contains a file upload control, a "Import Data" button, a "newTransactions" <asp:table>, a"SaveTrans" button and an confMsg label. First the...
1
by: somaskarthic | last post by:
Hi In my application , i need to create table rows at runtime. Using javascript with table id arguments i could replicate the rows at runtime. Each of these rows has checkboxes (7.no) , dropdown...
7
by: leiño | last post by:
Hi, i am adding table rows dynamically with javascript. This works fine. The table is inside a div with scrolls, initially with 6 rows: ..... <div style='overflow:auto; width:100%;...
2
by: kalyanilovesme | last post by:
Hi I have a html table.. and i am adding the table rows dynamically... actually table rows are 64.. but according to the program some are visible and other are invisible.. i want to calculate...
5
by: Liquidtouch | last post by:
I'm not much of a HTML or Javascript programmer but have a little experience just hacking away at it. I am creating a HTML application and would like to be able to add or remove rows of a table....
2
by: Conrad Lender | last post by:
On 2008-10-10 19:56, T.G. wrote: This doesn't work at all, at least not in Firefox. When any of the "up" or "down" links is clicked, the following error occurs: clickedRow.removeNode is not a...
1
by: vivek kapile | last post by:
Title:Dynamically adding table row with a checkbox using JavaScript Author:Vivek Kapile Email:snipped Language:JavaScript Platform:JavaScript in ASP.net Technology:Used in ASP.net...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
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
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
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...

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.