Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Colspan gridview单击“打印”按钮后展开更多列_C#_Asp.net_.net_Gridview - Fatal编程技术网

C# Colspan gridview单击“打印”按钮后展开更多列

C# Colspan gridview单击“打印”按钮后展开更多列,c#,asp.net,.net,gridview,C#,Asp.net,.net,Gridview,我有下面的网格视图有4列 我在页脚中合并了一些列 我在点击printbn后遇到的问题网格视图在页脚中增加了两列 因此输出将是原始网格视图列加上网格视图页脚中的两个空列 栅格视图 <asp:GridView ID="grid" runat="server" ShowFooter="true" DataSourceID="SqlDs_Grid" OnRowDataBound="grid_RowDataBound" AutoGenerateColumns="false" CssClass="ta

我有下面的网格视图有4列

我在页脚中合并了一些列

我在点击
printbn
后遇到的问题网格视图在页脚中增加了两列

因此输出将是原始网格视图列加上网格视图页脚中的两个空列

栅格视图

<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();
        }
}
protectedvoid grid\u RowDataBound(对象发送方,GridViewRowEventArgs e)
{
if(e.Row.RowType==DataControlRowType.Footer)
{
e、 行细胞移除(1);
e、 行细胞去除(2);
e、 行。单元格[0]。列span=3;
e、 行.单元格[0].Text=“文字总量
”+“”+NumberToWords(Convert.ToInt32(Totalamount))+“仅限”; e、 行。单元格[1]。Text=“总额:”; 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();" />

发生此问题的原因是,单击按钮会导致回发。要防止出现这种情况,请在
OnClientClient
事件中返回
false

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