简体   繁体   English

使用javascript更改在中继器中选择的行的颜色

[英]change color of row selected in repeater with javascript

I have a repeater with a linkbutton. 我有一个带有linkbutton的中继器。 So, I intend to use javascript to when click the linkbutton, in addition to be able to make data editing, can change the color of selected row. 因此,我打算在单击链接按钮时使用javascript,除了能够进行数据编辑之外,还可以更改所选行的颜色。

but I do not know how to do this. 但我不知道该怎么做。 Can I add an OnClientClick event? 我可以添加OnClientClick事件吗? how can I know the line that you selected to be able to change the color? 我怎么知道您选择的能够更改颜色的线?

Thank you... 谢谢...

<asp:Repeater ID="Repeater1" runat="server" >
  <HeaderTemplate>
        <table>
   </HeaderTemplate>
      <ItemTemplate>
       <tr class="trclass" style="width:100px">
        <td>
            <asp:LinkButton ID="LinkBtn1" OnCommand="lbEdit_Command" 
                   CommandArgument='<%# Eval("ID")%>'
                    CommandName="EDIT" runat="server">
                </asp:LinkButton>
        </td>
      </tr>
   </ItemTemplate>
   <FooterTemplate>
        </table>
   </FooterTemplate>
</asp:Repeater>

You can use OnClientClick event. 可以使用OnClientClick事件。 Inside client-click "this" refers to element caused the event, so you can try something like: 在客户端中单击“ this”是指导致事件的元素,因此您可以尝试以下操作:

<asp:LinkButton ID="LinkBtn1" OnCommand="lbEdit_Command" 
    CommandArgument='<%# Eval("ID")%>'
    CommandName="EDIT" runat="server">
    OnClientClick = "this.parentElement.style.backgroundColor = 'blue'"
</asp:LinkButton>

this will select parent element of the clicked link which is TD and set it's background color to blue. 这将选择单击的链接的父元素TD,并将其背景色设置为蓝色。 A (probably better) alternative would be assign a CSS class instead of assigning color directly. 一个(可能更好)的替代方案是分配一个CSS类,而不是直接分配颜色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM