• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 867
  • Last Modified:

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

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
            Next
        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">
    <HeaderTemplate>
        <table border="1" cellpadding="0" cellspacing="0" style="width:98%">
            <tr style="width:10%; background-color:Black; color:white">
                <td>Image</td>
                <td style="width:10%">Lot Number</td>
                <td style="width:60%">Description</td>
                <td style="width: 20%">Special Operations</td>
            </tr>
    </HeaderTemplate>
    <ItemTemplate>
            <tr>
                <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") %> '/>
                    </asp:HyperLink>
                </td>
                <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>
                </td>
            </tr>
    </ItemTemplate>
    <FooterTemplate>
        </table>
    </FooterTemplate>
</asp:Repeater>

Open in new window

0
dzumwalt
Asked:
dzumwalt
  • 2
1 Solution
 
Juan_BarreraCommented:
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")
                    'Or:
                    c.BackColor = Drawing.Color.Green
                End If
            Next
        End If

Open in new window

0
 
dzumwaltAuthor Commented:
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?
0
 
dzumwaltAuthor Commented:
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?
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now