【问题标题】:Using Eval on div inside DataList ItemTemplate for MouseOver?在 DataList ItemTemplate 中的 div 上使用 Eval 进行 MouseOver?
【发布时间】:2016-08-29 00:57:03
【问题描述】:

对于令人费解的标题,我深表歉意。

我有一个DataList,如下所示:

<asp:DataList ID="DataListFloor" runat="server" RepeatColumns="5" >
    <ItemTemplate>
        <div style='width:199px;height:166px;background-color: <%# Eval("background") %>'>
            <div style="width: 199px; height: 22px; overflow: hidden;">
                <div style="box-sizing: border-box; width:97px; float:left;">
                    <asp:Label ID="Label1" runat="server" Text='<%# Eval("Name")%>'></asp:Label>
                </div>
            </div>
        </div>
    </ItemTemplate>
</asp:DataList>

要绑定到这个DataList 的数据表是:

Name    background  background_mouseOver
----------------------------------------
Joe     Yellow      Orange
Mary    white       Beige
Jane    Red         Maroon
Carl    gray        Darkgray

divbackground-color 已设置为background 列中的颜色。所以我知道该属性的 Eval 有效。

我的问题是:如何将MouseOver 上的divbackground-color 更改为datatablebackground_mouseOver 中的值。例如,对于显示 Joe 的数据列表项,背景颜色将为 Yellow。当我将光标移到该单元格上时,背景颜色将变为 Orange

请不要使用 jquery。

谢谢。

【问题讨论】:

    标签: javascript html css asp.net visual-studio-2010


    【解决方案1】:

    我最终以这种方式使用onMouseover

    <div onMouseover="this.style.backgroundColor = '<%# Eval("background_mouseOver")%>'" style='background-color: <%# Eval("background") %>'>
    </div>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-09
      • 1970-01-01
      相关资源
      最近更新 更多