开发者

how to change repeater row back color on checkbox check using java script asp.net

开发者 https://www.devze.com 2023-02-19 17:00 出处:网络
I want to change back color of repeater row when a particular row che开发者_如何学Pythonck box is checked client side or whenever a row td is clicked.For that the simplest way is that you will need to

I want to change back color of repeater row when a particular row che开发者_如何学Pythonck box is checked client side or whenever a row td is clicked.


For that the simplest way is that you will need to output your markup in tabular format like below code:

<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
    <HeaderTemplate>
    <table>
    </HeaderTemplate>
    <ItemTemplate>
    <tr class="trclass" style="width:100px">
    <td>
        <asp:CheckBox ID="CheckBox1" runat="server" Text=""/>
    </td>
    </tr>
    </ItemTemplate>
    <FooterTemplate>
    </table>
    </FooterTemplate>
    </asp:Repeater>

  <style type="text/css">
    .backg
    {
        background-color:Blue;
    }
    </style>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $("[id$='_CheckBox1']").click(function () {
                var checked = $(this).is(':checked');
                if (checked == true) {
                    $(this).parent().parent().addClass("backg");
                }
                else {
                    $(this).parent().parent().removeClass("backg");
                }
            });
            $(".trclass").click(function() {
            if ($(':checkbox', this).is(':checked')) {
                $(this).addClass("backg");
            }
            else {
                $(this).removeClass("backg");
            }
        });
        });
    </script>

There is a minor flaw but let me know if this is what you are looking for and we can fix it.

Edited: I have updated the tr click code. See if that's what you want. If not can you update your question to clarify when you want the row color to change exactly and if the checbox is affected on row click?

Edit 2: I came across this link which might be helpful.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号