0

私は30行のグリッドビューを持っています。それぞれ10行の3ページに印刷したいです。このコードを試しました。

        foreach (GridViewRow row in GridView1.Rows)
        {
            if (row.RowIndex % 10 == 0 && row.RowIndex != 0)
            {
                row.Attributes["style"] = "page-break-after:always;";
            }
        }

しかし、改ページなしでページ全体を印刷します。以前は、javascript を使用して印刷機能を呼び出していました (以下を参照)。

    function PrintGridData() {
        var prtGrid = document.getElementById('<%=GridView1.ClientID %>');
        prtGrid.border = 0;
        //GridView1.Attributes(style) = "page-break-after:always"         
        var prtwin = window.open('', 'PrintGridViewData', 'left=100,top=100,width=1000,height=1000,tollbar=0,scrollbars=1,status=0,resizable=1');
        prtwin.document.write(prtGrid.outerHTML);
        prtwin.document.close();
        prtwin.focus();
        prtwin.print();
        prtwin.close();
    }

ヘルプ???

よろしく...

以下に完全なマークアップを示しています..plsはそれをチェックしてください..

<%@ Page Title="About Us" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="About.aspx.cs" Inherits="WebApplication2.About" EnableEventValidation="false" %>

<%@ Register assembly="Shared.WebControls" namespace="Shared.WebControls" tagprefix="cc1" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <h2>
        About
    </h2>
    <script type="text/javascript">

        function PrintGridData() {
            var prtGrid = document.getElementById('<%=ReportGridView1.ClientID %>');

                //window.print();
            prtGrid.border = 0;
            //GridView1.Attributes(style) = "page-break-after:always"         
            var prtwin = window.open('', 'PrintGridViewData', 'left=100,top=100,width=1000,height=1000,tollbar=0,scrollbars=1,status=0,resizable=1');
            prtwin.document.write(prtGrid.outerHTML);
            prtwin.document.close();
            prtwin.focus();
            prtwin.print();
            prtwin.close();
        }
</script>
   <p>
        <asp:Button ID="Button1" runat="server" Text="Button" 
             onclick="Button1_Click" OnClientClick="PrintGridData()"/>
&nbsp;<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" 
            CellPadding="4" DataKeyNames="ID" DataMember="DefaultView" 
            ForeColor="Black" GridLines="None" 
            ShowFooter="True" style="margin-left: 0px; margin-right: 0px; margin-top: 3px;" 
            Width="965px" 
            ShowHeaderWhenEmpty="True" 
            EnableTheming="True" onrowcreated="GridView1_RowCreated" 
            onrowdatabound="GridView1_RowDataBound">
            <AlternatingRowStyle BackColor="White" BorderStyle="Solid" />
            <Columns>
                <asp:TemplateField ConvertEmptyStringToNull="False" HeaderText="Select">
                    <ItemTemplate>
                        <asp:CheckBox ID="chkrow" runat="server" AutoPostBack="True" 
                            TabIndex="1" ToolTip="Select" />
                    </ItemTemplate>
                    <HeaderTemplate>
                        <asp:CheckBox ID="chkhead" runat="server" />
                    </HeaderTemplate>
                </asp:TemplateField>
                <asp:CommandField ButtonType="Button" HeaderText="Edit" ShowEditButton="True">
                <ControlStyle CssClass="classname" />
                </asp:CommandField>
                <asp:TemplateField HeaderText="First Name">
                    <ItemTemplate>
                        <asp:Label ID="lblfirstname" runat="server" Text='<%# Eval("First_name") %>'></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txteditfirstname" runat="server" 
                            Text='<%# Eval("First_name") %>'></asp:TextBox>
                    </EditItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Second Name">
                    <ItemTemplate>
                        <asp:Label ID="lblsecondname" runat="server" Text='<%# Eval("Second_name") %>'></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txteditsecondname" runat="server" 
                            Text='<%# Eval("Second_name") %>'></asp:TextBox>
                    </EditItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="DOB">
                    <ItemTemplate>
                        <asp:Label ID="lbldob" runat="server" Text='<%# Eval("DOB") %>'></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txteditdob" runat="server" Text='<%# Eval("DOB") %>'></asp:TextBox>
                    </EditItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Address">
                    <ItemTemplate>
                        <asp:Label ID="lbladdress" runat="server" Text='<%# Eval("Address") %>'></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txteditaddress" runat="server" Text='<%# Eval("Address") %>'></asp:TextBox>
                    </EditItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="PIN">
                    <EditItemTemplate>
                        <asp:TextBox ID="txteditpin" runat="server" Text='<%# Eval("PIN") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="lblpin" runat="server" Text='<%# Eval("PIN") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Contact No">
                    <ItemTemplate>
                        <asp:Label ID="lblcontactno" runat="server" Text='<%# Eval("Contact_no") %>'></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txteditcontactno" runat="server" 
                            Text='<%# Eval("Contact_no") %>'></asp:TextBox>
                    </EditItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="E-mail">
                    <ItemTemplate>
                        <asp:Label ID="lblemail" runat="server" Text='<%# Eval("E_mail")%>'></asp:Label>
                    </ItemTemplate>

                    <EditItemTemplate>
                        <asp:TextBox ID="txteditemail" runat="server" Text='<%# Eval("E_mail") %>'></asp:TextBox>
                    </EditItemTemplate>
                </asp:TemplateField>
            </Columns>
            <FooterStyle BackColor="#CCCC99" />
            <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
            <PagerSettings Visible="False" />
            <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
            <RowStyle BackColor="#F7F7DE" />
            <SelectedRowStyle BackColor="#CE5D5A" CssClass="SelectedRowStyle" 
                Font-Bold="True" ForeColor="White" />
            <SortedAscendingCellStyle BackColor="#FBFBF2" BorderStyle="Double" />
            <SortedAscendingHeaderStyle BackColor="#848384" />
            <SortedDescendingCellStyle BackColor="#EAEAD3" />
            <SortedDescendingHeaderStyle BackColor="#575357" />
        </asp:GridView>
</p>

ヘルプ???

4

2 に答える 2