2013-02-14 18 views
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隱藏GridView控件的兩列,而在打印Asp.net

+0

我同意史蒂夫回答,你應該修改你的函數HidColumn()返回true或false .. – Pranav 2013-02-14 11:38:28

回答

0

此行沒有任何意義:var b = HidColumn();

功能HidColumn沒有按」 t返回任何東西。

0

正如我所說,我同意史蒂夫的答案,你應該修改你的函數HidColumn返回true或false。 還有一點我想提到,如果你從點擊返回false()然後postback將不會發生,否則它會在服務器上調用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" /> 
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(); 
    }