Ramco Ramco

Ramco Ramco

  • 438
  • 3.4k
  • 542.3k

Background color getting cleared

Jun 20 2023 6:33 AM

Hi

   I have below code . Problem is on Dropdown PostBack BackGround color gets cleared

<asp:DropDownList ID="ddlBook" class="form-control" required="true" parsley-trigger="change" runat="server" OnSelectedIndexChanged="ddlBook_SelectedIndexChanged" AutoPostBack="true">
                                                    <asp:ListItem Value="">Select Book</asp:ListItem>
                                                </asp:DropDownList></td>

<script>
        var ddl = document.getElementById("ddlBook");
        ddl.addEventListener("change", function () {
            var selectedText = ddl.selectedOptions[0].textContent;
            var table = document.getElementById("tbldata"); // Replace "myTable" with the ID of your table

            for (var i = 0; i < table.rows.length; i++) {
                var row = table.rows[i];
                var cell = row.cells[7];

                if (cell.textContent == selectedText) {
                    alert(cell.textContent);
                    alert(selectedText);
                    cell.style.backgroundColor = "yellow"; 
                }
            }
        });
    </script>

Thanks


Answers (1)