0

If I wanted to loop through the img src of the following cells uisng a For Each loop and set the src for each of them based on another value (x) can I explicity reference the img src attributes in code, or is it better to embed the table in a control further up the hierarchy. Or maybe this would be better actioned client side with javascript? I have written a basic function to check the value of x as below. Am I on the right lines?

    Public Function GetCheckbox(ByVal x As Integer) As String
            Dim checkboxSrc As String = String.Empty
            Dim checked As String = "~/graphics/checkbox-checked.jpg"
            Dim unchecked As String = "~/graphics/checkbox-unchecked.jpg"

            If x = 1 Then
                checkboxSrc = checked
            ElseIf x = 0 Then
                checkboxSrc = unchecked
            End If
            Return checkboxSrc
        End Function


<table id="tblHolisticConcerns" runat="server" border="2" >               
                    <tr id="trPracticalConcerns2" runat="server">                              
                        <td style="width:20%; height:25px; vertical-align:middle"><img id="img2" alt="Holistic Checkbox" runat="server" src="" style="width:16px; height:16px" />&nbsp;Child Care<asp:Literal ID="litChildCare" runat="server"></asp:Literal></td>
                        <td style="width:20%; height:25px; vertical-align:middle"><img id="img3" alt="Holistic Checkbox" runat="server" src="" style="width:16px; height:16px" />&nbsp;Communication<asp:Literal ID="litCommunication" runat="server"></asp:Literal></td>
                        <td style="width:20%; height:25px; vertical-align:middle"><img id="img4" alt="Holistic Checkbox" runat="server" src="" style="width:16px; height:16px" />&nbsp;Household Tasks<asp:Literal ID="litHouseholdTasks" runat="server"></asp:Literal></td>
                        <td style="width:20%; height:25px; vertical-align:middle"><img id="img5" alt="Holistic Checkbox" runat="server" src="" style="width:16px; height:16px" />&nbsp;Housing<asp:Literal ID="litHousing" runat="server"></asp:Literal></td>
                        <td style="width:20%; height:25px; vertical-align:middle"><img id="img6" alt="Holistic Checkbox" runat="server" src="" style="width:16px; height:16px" />&nbsp;Insurance<asp:Literal ID="litInsurance" runat="server"></asp:Literal></td>
                    </tr>
    </table>
4

1 回答 1

0

是的,根据您的标记,您可以像这样遍历所有图像:

For Each oRow As HtmlTableRow In tblHolisticConcerns.Rows

  CType(oRow.Cells(0).Controls(0), HtmlImage).Src = GetCheckbox(Value)

Next
于 2013-08-08T17:26:18.190 回答