Setting back color on repeater row. I can't see a HtmlTableCell control.

Posted on 2008-11-11
Last Modified: 2012-05-05
I have seen the solution in Question # 21206598 where the ItemDataBound event is scanning for a HtmlTableCell object as follows:

    Protected Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles Repeater1.ItemDataBound

        If e.Item.ItemType = ListItemType.Item Then
            For i As Integer = 0 To e.Item.Controls.Count - 1
                If e.Item.Controls(i).GetType() Is GetType(HtmlTableCell) Then
                    Dim c As HtmlTableCell = CType(e.Item.Controls(i), HtmlTableCell)
                    c.BgColor = "Green"
                End If
        End If

    End Sub

My problem is that it NEVER finds an HTMLTableCell. My ASP code is as follows:

What am I missing?
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="sqldsAuctionCatalog">


        <table border="1" cellpadding="0" cellspacing="0" style="width:98%">

            <tr style="width:10%; background-color:Black; color:white">


                <td style="width:10%">Lot Number</td>

                <td style="width:60%">Description</td>

                <td style="width: 20%">Special Operations</td>





                <td style="width: 10%">

                    <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# "~/ItemDetails.aspx?ItemID=" & DataBinder.Eval(Container.DataItem,"LiveAuctionInventoryItemUniqueID") %> '>

                        <asp:Image ID="Photo" runat="server" ImageUrl='<%# "~/PhotoRetrievers/GetItemThumbnail.aspx?ItemID=" & DataBinder.Eval(Container.DataItem,"LiveAuctionInventoryItemUniqueID") & "&Sequence=" & DataBinder.Eval(Container.DataItem,"SequenceNumber") %> '/>



                <td style="width:10%; font-size:x-large" ><%#DataBinder.Eval(Container.DataItem,"LotNumber") & DataBinder.Eval(Container.DataItem,"LotSubLetter") %></td>

                <td style="width:60%; vertical-align: text-top; text-align:left" ><%#DataBinder.Eval(Container.DataItem,"ShortDescription") & " - " & DataBinder.Eval(Container.DataItem,"LongDescription") %></td>

                <td style="width: 20%">

                    <asp:Button ID="btnEnterAbsenteeBid" runat="server" Style="z-index: 100; left: 0px; position: static; top: 0px; width:100%" Text='Enter Absentee Bid' CommandName="ABSENTEEBID" CommandArgument='<%# DataBinder.Eval(Container.DataItem,"LiveAuctionInventoryItemUniqueID") %>' ></asp:Button>

                    <asp:Button ID="btnEnterConditionReportRequest" runat="server" Style="z-index: 100; left: 0px; position: static; top: 0px; width:100%" Text='Request Condition Report' CommandName="CONDRPTREQ" CommandArgument='<%# DataBinder.Eval(Container.DataItem,"LiveAuctionInventoryItemUniqueID") %>' ></asp:Button>








Open in new window

Question by:dzumwalt
    LVL 20

    Accepted Solution

    Hi there,

    If I remember correctly, the control type for a TemplatedField in a Repeater is DataControlFieldCell. Give this a try:

       If e.Item.ItemType = ListItemType.Item Then
                For i As Integer = 0 To e.Item.Controls.Count - 1
                    Dim c As DataControlFieldCell = TryCast(e.Item.Controls(i), DataControlFieldCell)
                    If c IsNot Nothing Then
                        c.Style.Add("bgcolor", "Green")
                        c.BackColor = Drawing.Color.Green
                    End If
            End If

    Open in new window


    Author Comment

    Sorry for not getting back to this for so long!

    I tried that code but apparently the control isn't DataControlFieldCell because the following line:

    If c IsNot Nothing Then

    never returns true.

    Any idea what that type is? Can you see how to find out?

    Author Comment

    it appears that it is a System.Web.UI.DataBoundLiteralControl. which of course doesn't have a background  color property nor does it appear to have a style property to which I can add a property.

    Again ... any ideas?

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    755 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now