0

我有一个 ASP.NET 应用程序并使用ListView. 这ListView有行和列。这些列是名字、姓氏、电子邮件等...其中的每一个Control都是.ListViewLinkButton

我的点子:

如果用户将鼠标移到 a 上LinkButton,我希望他们BackroundColor在该行上看到不同的内容。

例如:

在此处输入图像描述

我的代码:

aspx:

<body>
    <form id="form1" runat="server">
    <div class="header">
        <br />
        <table id="SuchTabelle" runat="server" border="0">

            <tr>
                <th><asp:Label ID="id_SearchUser" runat="server" Text="lblSearchUser"></asp:Label></th>
                <th><asp:TextBox ID="txtBenutzer" runat="server" Width="250px"></asp:TextBox></th>
                <th></th>
            </tr>
            <tr>
                <th><asp:Label ID="id_location" runat="server" Text="lblLocation"></asp:Label></th>
                <th><asp:DropDownList ID="dropWerk" runat="server" Width="250px" /></th>
                <th><asp:Button ID="Button2" runat="server" Text="Suchen" 
                                onclick="btnBenutzerSuchen_Click" Width="250" /></th>
            </tr>

        </table>

        <br />
        <br />
       <b>&nbsp;&nbsp;&nbsp; Info:</b> 
        <asp:Label ID="lbMeldung" runat="server" 
            Text="Geben Sie den Kontakt ein, nachdem gesucht werden soll..."></asp:Label>
        <br />
      <br />
      </div>

      <div class="bodyList">


        <asp:ListView runat="server" ID="myListView">

        <LayoutTemplate>
            <table id="UserTable" runat="server" border="0">
                <tr id="Tr1" style="background-color:#E5E5FE">
                    <th runat="server"><asp:LinkButton ID="lnkBenutzer" runat="server" >id_Benutzer</asp:LinkButton></th>
                    <th runat="server"><asp:LinkButton ID="lnkemail" runat="server" >id_Email</asp:LinkButton></th>
                    <th runat="server"><asp:LinkButton ID="lnkVorname" runat="server" >id_Vorname</asp:LinkButton></th>
                    <th runat="server"><asp:LinkButton ID="lnkNachname" runat="server" >id_Nachname</asp:LinkButton></th>
                    <th runat="server"><asp:LinkButton ID="lnkTelefon" runat="server" >id_Telefon</asp:LinkButton></th>
                </tr>
                <tr runat="server" id="ItemPlaceholder">
                </tr>
            </table>
        </LayoutTemplate>

        <ItemTemplate>

            <tr>    
                <td align="left" ><asp:LinkButton CssClass="MyLink" OnCommand="Button1_Command" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label1" Text='<%# Eval("Benutzername") %>' runat="server" /></td>
                <td align="left"><asp:LinkButton CssClass="MyLink" OnCommand="Button1_Command" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label2" Text='<%# Eval("eMail") %>' runat="server" /></td>
                <td align="left"><asp:LinkButton CssClass="MyLink" OnCommand="Button1_Command" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label3" Text='<%# Eval("Vorname") %>' runat="server" /></td>
                <td align="left"><asp:LinkButton CssClass="MyLink" OnCommand="Button1_Command" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label4" Text='<%# Eval("Nachname") %>' runat="server" /></td>
                <td align="left"><asp:LinkButton CssClass="MyLink" OnCommand="Button1_Command" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label5" Text='<%# Eval("Telefonnummer") %>' runat="server" /></td>

              <td align="left"><asp:Label ID="Label6" Text='<%# Eval("GUID") %>' runat="server" Visible="False" /></td>

            </tr>

        </ItemTemplate>

        <AlternatingItemTemplate>

            <tr style="background-color:#EFEFEF"> 

                <td align="left" ><asp:LinkButton CssClass="MyLink" OnCommand="Button1_Command" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label1" Text='<%# Eval("Benutzername") %>' runat="server" /></td>
                <td align="left"><asp:LinkButton CssClass="MyLink" OnCommand="Button1_Command" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label2" Text='<%# Eval("eMail") %>' runat="server" /></td>
                <td align="left"><asp:LinkButton CssClass="MyLink" OnCommand="Button1_Command" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label3" Text='<%# Eval("Vorname") %>' runat="server" /></td>
                <td align="left"><asp:LinkButton CssClass="MyLink" OnCommand="Button1_Command" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label4" Text='<%# Eval("Nachname") %>' runat="server" /></td>
                <td align="left"><asp:LinkButton CssClass="MyLink" OnCommand="Button1_Command" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label5" Text='<%# Eval("Telefonnummer") %>' runat="server" /></td>

                <td align="left"><asp:Label ID="Label6" Text='<%# Eval("GUID") %>' runat="server" Visible="False" /></td>

            </tr>

        </AlternatingItemTemplate>

        </asp:ListView>

        <br />
        <br />

    </div>

    </form>
</body>
4

1 回答 1

1

您可以使用 CSS:

<LayoutTemplate>
    <table id="UserTable" runat="server" class="myClass">
        <tr id="Tr1" class="myClass">
            <th id="Th1" runat="server">
                <asp:LinkButton ID="lnkBenutzer" runat="server" Text="id_Benutzer" />
            </th>
            <th id="Th2" runat="server">
                <asp:LinkButton ID="lnkemail" runat="server" Text="id_Email" />
            </th>
            <th id="Th3" runat="server">
                <asp:LinkButton ID="lnkVorname" runat="server" Text="id_Vorname" />
            </th>
            <th id="Th4" runat="server">
                <asp:LinkButton ID="lnkNachname" runat="server" Text="id_Nachname" />
            </th>
            <th id="Th5" runat="server">
                <asp:LinkButton ID="lnkTelefon" runat="server" Text="id_Telefon" />
            </th>
        </tr>
        <tr runat="server" id="ItemPlaceholder">
        </tr>
    </table>
</LayoutTemplate> 

在 *.css 文件中:

.myClass
{

}

.myClass:hover
{
background-color: Green;
}
于 2012-08-07T12:50:20.007 回答