0

我有一个如下所示的转发器对象

<asp:Repeater id="rptSpecialNotes" runat="server">
                    <headerTemplate><ol type="A"></HeaderTemplate>
                    <itemtemplate>
                                <li>
                                </li>
                        <asp:UpdatePanel ID="udpSpecialNotesRepeater" runat="server" UpdateMode="Always">
                            <ContentTemplate>

                                    <div id="specialNotes" name='<%# Eval("itemId") %>' runat="server">
                                        <asp:imagebutton runat="server"  width="20" class="floatLeft" id="specialNotesItem" imageurl='<%# Eval("ImageUrl") %>'  commandname="specialNotesImageChange" commandargument='<%# Eval("itemId") %>'></asp:imagebutton>
                                        <span class="subject"><p><%# eval("Subject") %></p></span>
                                        <br /><br />
                                        <p><%# Eval("AgendaNote")%></p>
                                        <br />
                                    </div>

                            </ContentTemplate>
                            <Triggers>
                                <asp:AsyncPostBackTrigger ControlID ="followAlongControl" EventName ="Tick" />
                            </Triggers>
                        </asp:UpdatePanel>
                        <asp:Repeater id="specialNotesAttachmentsRepeater" OnItemCommand="specialNotesAttachmentRepeater_ItemCommand" runat="server" datasource='<%# Container.DataItem.Row.GetChildRows("attachmentRelation") %>' >
                            <itemtemplate>
                                <br />
                                <a href='<%# Container.DataItem("attachmentPath") %>'><%# Container.DataItem("attachmentName") %></a>&nbsp;&nbsp;
                                </itemtemplate>
                        </asp:Repeater>
                    </itemtemplate>
                    <footerTemplate></ol></FooterTemplate>
                </asp:Repeater>

我想根据图像按钮的 imageurl 更改 div 'specialNotes' 的背景颜色。因此,如果选中,则 div 将为灰色,如果没有,则将其留空。

有没有办法在 VB 的代码隐藏中做到这一点?

4

3 回答 3

1

将 a 添加runat="server"到您的 div 标签。然后您的代码在后面,您可以使用以下命令访问该 div:

udpSpecialNotesRepeater.FindControl("div")

在您的 DataBound 事件上。

不过,在 jQuery 中执行此操作要容易得多。您可以只获取 div 的 id$("#specialNotes")并使用该.attr函数来更改其背景。

于 2013-04-16T22:04:14.943 回答
1

您不必在页面加载后“查找”div,您可以在它被绑定时执行此操作。我想当你说“如果它被选中”时,你指的是 imagebutton 作为一个复选框,并且你想根据图像的位置(路径)来改变颜色。所以我会在 div 中这样做:

<div style='<%# doColor(Eval("ImageUrl")) %>'>
    Content in the div
</div>

然后在后面的代码中:

Public Function doColor(img As Object) As String
    If img.ToString() = "MyPath" Then
        Return "background-color:red"
    Else
        Return "background-color:green"
    End If
End Function

这样,如果 ImageUrl 等于“MyPath”,则 div 的背景将为红色,否则为绿色。

于 2013-04-16T22:11:06.017 回答
0

可以使用:

Control divControl=e.Item.FindControl("divControl"); 
于 2017-05-24T07:23:18.987 回答