0
 function printform() {
        var printContent = document.getElementById("<%= PrintPanelID.ClientID %>");

        var windowUrl = "about:blank";
        var uniqueName = new Date();
        var windowName = "Print" + uniqueName.getTime();
        var printWindow = window.open(windowUrl, windowName, "left=50000,top=50000,width=0,height=0");
        printWindow.document.write(printContent.innerHTML);
        printWindow.document.close();
        printWindow.focus();
        printWindow.print();
        printWindow.close();
    }

    function HidColumn() {

        // col_num = document.getElementById("Button").value;
        rows = document.getElementById("<%= GV1.ClientID %>").rows;
        for (i = 0; i < rows.length; i++) {
            rows[i].cells[8].style.display = "none";
        }

        for (j = 0; j < rows.length; j++) {
            rows[j].cells[9].style.display = "none";
        }
    }

    // change logic to suit taste
    function clicked() {
        var b = HidColumn();
        if (b)
            printform()
        return b;
    }


  <asp:ImageButton ID="ImageButton2" runat="server" ImageAlign="Right" ImageUrl="images/printer.jpg"
                    Style="margin-left: 5px; margin-right: 15px" OnClick="ImageButton2_Click" Width="36px"
                    OnClientClick="return clicked()" Visible="false" />

但是,当我单击 ImageButton 时什么也没有发生

4

3 回答 3

0

正如我所说,我同意史蒂夫的回答,您应该修改您的函数 HidColumn 以返回真或假。还有一点我想提一下,如果您从 clicked() 返回 falsepostback则不会发生,否则它将ImageButton2_Click在服务器上调用事件。

function HidColumn() {

        // col_num = document.getElementById("Button").value;
        rows = document.getElementById("<%= GV1.ClientID %>").rows;
        for (i = 0; i < rows.length; i++) {
            rows[i].cells[8].style.display = "none";
        }

        for (j = 0; j < rows.length; j++) {
            rows[j].cells[9].style.display = "none";
        }
        if(someCondition)return true;
         else return false;
    }

更新:- 您已将控件可见性设置为 False ,因此不会呈现控件。因此,您无法在 javascript 中获取元素,因为该控件将没有 HTML。如果您想隐藏控件,只需使用 Javascript:-

<asp:somecontrol id="ctrl" style="display:none" />
于 2013-02-14T11:44:28.540 回答
0

只需将您的隐藏列代码放在打印函数中,如下所示:

function PrintPage() {

        rows = document.getElementById("<%= Gv1.ClientID %>").rows;
        for (i = 0; i < rows.length; i++) {
            rows[i].cells[8].style.display = "none";
            rows[i].cells[9].style.display = "none";
        }
        var printContent = document.getElementById('<%= pnlDtls.ClientID %>');
        var printWindow = window.open("All Records", "Print Panel", 'left=50000,top=50000,width=0,height=0');
        printWindow.document.write(printContent.innerHTML);
        printWindow.document.close();
        printWindow.focus();
        printWindow.print();
    }
于 2014-12-10T07:13:54.873 回答
0

这行没有意义: var b = HidColumn();

函数 HidColumn 不返回任何内容。

于 2013-02-14T11:36:12.940 回答