Solved

cannot convert from 'System.Web.UI.HtmlControls.HtmlTableRow' to 'System.Web.UI.WebControls.TableRow'

Posted on 2003-10-31
1
3,068 Views
Last Modified: 2012-08-14
I am getting the following error when I try to add a row to a table

cannot convert from 'System.Web.UI.HtmlControls.HtmlTableRow' to 'System.Web.UI.WebControls.TableRow'

I am using the following code snippet to add a row to the table

HtmlTableRow objRow = new HtmlTableRow();
HtmlTableCell objCell = new HtmlTableCell();
objCell.InnerHtml += ds.Tables[0].Rows[0][0].ToString();
objRow.Cells.Add(objCell);

Table1.Rows.Add(objRow)

The element Table1 is there in the aspx file.

<asp:Table id="Table1"
style="Z-INDEX: 102; LEFT: 72px; POSITION: absolute; TOP: 56px"
runat="server"
Width="192px">
</asp:Table>

Any ideas would be appreciated.
0
Comment
Question by:rxraza
1 Comment
 
LVL 6

Accepted Solution

by:
zrh earned 20 total points
ID: 9661884
Well, a HtmlTableRow is for a HtmlControls.HtmlTable, a TableRow is for a WebControls.Table (two different beasts).  

This is a HtmlTable control:
<table runat="server" id="myHtmlTable">
     ...
</table>

This is a Table WebControl:
<asp:Table id="myTableWebControl" runat="server">
    ...
</asp:Table>

Try doing something like:
TableRow objRow = new TableRow();
TableCell objCell = new TableCell();
objCell.Text += ds.Tables[0].Rows[0][0].ToString();
objRow.Cells.Add(objCell);

Table1.Rows.Add(objRow)

Hope that helps,
ZRH
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Need help parsing JSON in my VB.Net application 4 97
ASP.NET 5 Templates 2 79
Get Client IP on RDS - VB.NET 15 48
C# Gridview 1 33
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question