Link to home
Avatar of Starr Duskk
Starr DuskkFlag for United States of America

asked on

How to Add Class and Styles to HTML Table in Code Behind without 'System.Web.UI.HtmlControls.HtmlGenericControl' cannot be converted to 'System.Web.UI.HtmlControls.HtmlTableRow'.

I want to programmatically add the class and/or styles to an html table in
I'm getting this error. I'm using Visual Studio 2015.

When I build, I get this error and the code behind doesn't recognize the element:
 'System.Web.UI.HtmlControls.HtmlGenericControl' cannot be converted to 'System.Web.UI.HtmlControls.HtmlTableRow'.

<table id="TableAvailableRepeater"  runat="server" class="display scrollTable" style="width: 100%; text-align: left !important; white-space: nowrap; overflow: auto;">
 <tbody id="dataContainerAvailable" clientidmode="Static" runat="server">
                                    <asp:Repeater ID="repAvailableRepeater" runat="server">
                                            <%# Eval("dcBuildRow").ToString()%>

Open in new window

I read there were problems with VS2012 that caused this problem when there is a tbody or thead, but this is VS2015 and I removed the tbody and the error still occurrec.

This is the type of codebehind I'm hoping to use.

            Dim addClass = "display scrollTable"
            TableAvailableRepeater.Attributes.Add("class", addClass)
            TableAvailableRepeater.Attributes.Add("style", "width: 100%; text-align: left !important; white-space: nowrap; overflow: auto;")

Open in new window

Any ideas how to get this to work without the error?

Avatar of Alfredo Luis Torres Serrano
Alfredo Luis Torres Serrano
Flag of United States of America image

Blurred text
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Starr Duskk


wasn't exactly what I hoped for, but if .net can't do it, what can you do. thanks!