2016-04-15 58 views
1

我有下面的網格視圖有4列。Colspan gridview在單擊打印按鈕後展開更多列

我已經合併了頁腳中的一些列。

點擊printbtn後,網格視圖會在頁腳中增加兩列。

因此,輸出將是網格視圖頁腳中的原始網格視圖列加上2個空列。

網格視圖

<asp:GridView ID="grid" runat="server" ShowFooter="true" DataSourceID="SqlDs_Grid" OnRowDataBound="grid_RowDataBound" AutoGenerateColumns="false" CssClass="table"> 
<Columns> 
    <asp:BoundField HeaderText="Sr.No"></asp:BoundField> 
    <asp:BoundField DataField="ProductName" HeaderText="Item Description" SortExpression="ProductName"></asp:BoundField> 
    <asp:BoundField DataField="ProductQty" HeaderText="Quantity" SortExpression="ProductQty"></asp:BoundField> 
    <asp:BoundField DataField="UnitPrice" HeaderText="Unit Price"></asp:BoundField> 
    <asp:BoundField HeaderText="Total Amount" /> 
</Columns> 

背後碼

protected void grid_RowDataBound(object sender, GridViewRowEventArgs e) 
{ 

     if (e.Row.RowType == DataControlRowType.Footer) 
     { 
      e.Row.Cells.RemoveAt(1); 
      e.Row.Cells.RemoveAt(2); 
      e.Row.Cells[0].ColumnSpan = 3; 
      e.Row.Cells[0].Text = "<div class='pull-left'>Total Amount In Words </div> <br>" + "<div class='pull-left'>" + NumberToWords(Convert.ToInt32(Totalamount)) + "Only</div>"; 
      e.Row.Cells[1].Text = "Total Amount:"; 
      e.Row.Cells[2].Text = Totalamount.ToString(); 
     } 
} 

打印按鈕

<asp:Button ID="printbtn" runat="server" Text="Print" CssClass="btn btn-primary hidden-print" OnClientClick="javascript:window.print();" /> 

回答

2

問題發生是因爲按鈕單擊導致回發。爲防止發生這種情況,請在OnClientClient事件中返回false

<asp:Button ... OnClientClick="javascript:window.print(); return false;" /> 
相關問題