locked
java script is not working for styles in gridview RRS feed

  • Question

  • User-600437734 posted

    Hi ,

    I am using .Net 4.5 framework and using jquery-1.9.1.min.js.

    my javascript code is

    gridview[i].cells[4].style.display = "none";

    it is not working.

    how to resolve this.

    I am hiding grid columns dynamically using Java script.

    Tuesday, May 8, 2018 9:43 PM

Answers

  • User36583972 posted

    Hi Tejasvi,

    I am hiding grid columns dynamically using Java script.

    You can try the following code.

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script language="JavaScript">
            function hideColumn() {
                col_num = document.getElementById("column_numbder").value;
                rows = document.getElementById("GridView1").rows;
                for (i = 0; i < rows.length; i++) {
                    rows[i].cells[col_num].style.display = "none";
                }
                 return false;
            }
        </script>
    
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:GridView ID="GridView1" runat="server">
                </asp:GridView>
            </div>
            <input id="column_numbder" type="text">
            <br />
            <asp:Button ID="Button1" runat="server" Text="Hide" OnClientClick="Javascript:return hideColumn();" />
        </form>
    </body>
    </html>
    

    How to Hide GridView Column using Javascript on ButtonClick in asp.net
    https://stackoverflow.com/questions/21452582/how-to-hide-gridview-column-using-javascript-on-buttonclick-in-asp-net/21473510

    Best Regards,

    Yong Lu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 9, 2018 2:13 AM