如何使gridview从右到左打印数据

时间:2015-06-24 12:19:49

标签: asp.net

gridview image 如何使gridview从右到左打印数据,我需要column0到右边和column1等等

2 个答案:

答案 0 :(得分:0)

您可以以声明方式设置和绑定数据源中的列顺序。例如:

<asp:GridView ID="GridView1" runat="server">
    <Columns>
        <asp:BoundField DataField="Column1" HeaderText="Column1" />
    </Columns>
    <Columns>
        <asp:BoundField DataField="Column2" HeaderText="Column2" />
    </Columns>
    <Columns>
        <asp:BoundField DataField="Column3" HeaderText="Column3" />
    </Columns>
    <Columns>
        <asp:BoundField DataField="Column4" HeaderText="Column4" />
    </Columns>
</asp:GridView>

其中Column1是数据源中的列。

对其他列重复此操作。订单将从顶部到底部从左到右。所以在这种情况下,第2列的列为1。确保第1列的标记位于column2之前

答案 1 :(得分:0)

您好我使用打印面板并从右到左打印。 我将gridview放在这样的面板标签中:

<asp:Panel id="pnlContents" runat = "server" Direction="RightToLeft">
<asp:GridView ID="G1" runat="server" AutoGenerateColumns="false"  OnRowDataBound="MatchList_RowDataBound" Direction="RightToLeft">
                <Columns>
                <asp:BoundField HeaderText=" " /> 

                <asp:BoundField HeaderText="ID" DataField="ID" />

                <asp:BoundField HeaderText="first name" DataField="name" />

                <asp:BoundField HeaderText="last name" DataField="family" />

                <asp:BoundField HeaderText="father's name" DataField="father_name" />


            </Columns>
        </asp:GridView>

</asp:Panel>

我使用按钮打印gridview

<asp:Button ID="btnPrint" runat="server" Text="Print" OnClientClick = "return PrintPanel();" />

和这个要打印的脚本

&#13;
&#13;
<script type = "text/javascript">
        function PrintPanel() {
            var panel = document.getElementById("<%=pnlContents.ClientID %>");
            var printWindow = window.open('', '', 'height=400,width=800');
            printWindow.document.write('<html><head><title>print preview title</title>');
            printWindow.document.write('</head><body >');
            printWindow.document.write(panel.innerHTML);
            printWindow.document.dir = "rtl";
            printWindow.document.write('</body></html>');
            printWindow.document.close();
            setTimeout(function () {
                printWindow.print();
            }, 500);
            return false;
        }
    </script>
&#13;
&#13;
&#13;

此行使印刷品从右向左

&#13;
&#13;
printWindow.document.dir = "rtl";
&#13;
&#13;
&#13;