我有一个具有5列的GridView1,第一列是Delete行。当用户单击提交时,我要调用此函数以隐藏该列,同时运行vb.net代码,直到完成。

我可以提醒(这里2),但我不能这里3?不知道为什么?

      function hideColumn() {
        alert("here-1");
        col_num = 0;    // document.getElementById("column_numbder").value;
        alert("here-2");
        rows = document.getElementById("divMain.GridView1").rows;
        alert("here-3");
        for (i = 0; i < rows.length; i++) {
            rows[i].cells[col_num].style.display = "none";
         }
        alert("here-4");
    }


这是我的gridview信息:

 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="both" OnRowDeleting="Gridview1_RowDeleting"  >
                    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                    <Columns>
                        <asp:CommandField HeaderText="" ShowDeleteButton="True" ShowHeader="True" DeleteText="Remove"  />
                    </Columns>
                    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                    <HeaderStyle BackColor="#99ccff" Font-Bold="True" ForeColor="White" />
                    <EditRowStyle BackColor="#999999" />
                    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                </asp:GridView>

最佳答案

尝试删除元素。

window.onload = function () {

    var grid = document.getElementById('<%=GridView1.ClientID %>');

    var buttons = grid.getElementsByTagName("a");

    for (var i = 0; i < buttons.length; i++) {
        if (buttons[i].innerText === "Remove") {
            var button = buttons[i];
            button.addEventListener("click", handleClick, false);
        }
    }

    function handleClick(evt) {
        this.style.display = "none";
        evt.preventDefault();
    }
}


evt.preventDefault()是我能够测试的,您可能不需要它。

关于javascript - 无法在JavaScript中隐藏gridview列,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18211729/

10-12 00:11
查看更多