troubleshooting Question

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'.

Avatar of Starr Duskk
Starr DuskkFlag for United States of America asked on
ASP.NET
2 Comments1 Solution10 ViewsLast Modified:
I want to programmatically add the class and/or styles to an html table in asp.net.
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">
                                        <ItemTemplate>
                                            <%# Eval("dcBuildRow").ToString()%>
                                        </ItemTemplate>
                                    </asp:Repeater>
                                </tbody>
                            </table>
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;")



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

Thanks!
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros