asp.net lodop单个打印

1、首先在列表页面增加以下代码

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CertificateSearch.aspx.cs" Inherits="DTMIS.Web.StudentMG.CertificateSearch" %>



<!DOCTYPE html>





<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">



<html xmlns="http://www.w3.org/1999/xhtml">



<head>

    <title>StudentSearch</title>



    <script src="../js/jquery-1.4.4.min.js" type="text/javascript"></script>

    <script src="../js/My97DatePicker/WdatePicker.js"></script>

    <link href="../Include/StyleFile.css" type="text/css" rel="stylesheet">

	<script type="text/javascript">

	   

	    function SelectAll(tempControl) {

	        var theBox = tempControl;

	        xState = theBox.checked;

	        elem = theBox.form.elements;

	        for (i = 0; i < elem.length; i++) {

	            if (elem[i].type == "checkbox" && elem[i].id != theBox.id) {

	                if (elem[i].checked != xState) {

	                    elem[i].click();

	                }

	            }

	        }

	    }

	    function changecolor(cbo, o) {

	        var theBox = cbo;

	        var tr = document.getElementById(o);

	        if (theBox.checked) {

	            tr.style.backgroundColor = "#E0E0E0";

	        }

	        else {

	            tr.style.backgroundColor = "Transparent";



	        }

	    }

	    //批量打印

	    function PrintUrl() {



	        var canshu = "<%= canshu%>";

	        var canshuUrl = "";

	        var canshus = canshu.split('|');

            var chks = document.getElementsByName("DataGrid1_CheckSingle");

            if (chks != null && chks.length != 0) {

                var len = chks.length;

                for (var i = 0; i < len; i++) {

                    var chk = chks[i]

                    if (chk.checked) {

                        canshuUrl += canshus[i] + ",";

                    }

                }

            }

            if (canshuUrl != "") {

                var canshusub = canshuUrl.substr(0, canshuUrl.length - 1);

                window.open("CertificatePrintNew.aspx?canshu=" + canshusub);



            }

            else {

                alert("请选择需打印学员!");

            }

        }

    </script>

</head>

<body ms_positioning="GridLayout" bottommargin="0" leftmargin="0" topmargin="0" rightmargin="0"

    background="../Images/BackGround.gif">

    <form id="Form1" method="post" runat="server">

        <table height="100%" cellspacing="0" cellpadding="0" width="100%" border="0">

            <tr>

                <td valign="top" width="100%" background="../Images/BackGround.gif">

                    <table cellspacing="1" cellpadding="0" width="98%" align="center" border="0">

                        <tr>

                            <td bgcolor="#cccccc" height="23" width="70%">

                                   学员管理 -- 学员信息</td>

                            <td bgcolor="#cccccc" align="center" width="30%"> 

                            </td>

                        </tr>

                        <tr>

                            <td valign="top" colspan="2">

                                <br>

                                <asp:Panel ID="SearchPanel" runat="server" Width="100%">

                                    <table cellspacing="0" cellpadding="0" width="100%" align="center" border="0">

                                        <tr>

                                            <td bgcolor="#006d4a">

                                                <table cellspacing="1" cellpadding="1" width="100%" align="center" border="0">

                                                    <tr>

                                                        <td class="tr" align="center" colspan="4" height="22">

                                                            学员信息查询</td>

                                                    </tr>

                                                     <tr>

                                                       <td class="BDTD">

                                                            所属驾校</td>

                                                        <td class="WHITETD">

                                                            <asp:DropDownList ID="ddlDrvNo" runat="server">

                                                            </asp:DropDownList></td>

                                                      <td class="BDTD" width="15%">

                                                            学员姓名</td>

                                                        <td class="WHITETD" width="35%">

                                                            <asp:TextBox ID="txtS_Name" runat="server" Width="100px"></asp:TextBox></td>

                                                      <%--  <td class="WHITETD">

                                                           

                                                        </td>--%>

                                                    </tr>

                                                    <tr>                                                       

                                                       <td class="BDTD">

                                                            证件号</td>

                                                        <td class="WHITETD">

                                                            <asp:TextBox ID="txtS_IDCardNo" runat="server" Width="160px"></asp:TextBox>

                                                        </td>

                                                        <td class="BDTD">报名日期</td>

                                                        <td class="WHITETD">

                                                             <input runat="server" readonly="readonly" id="BgDate" onfocus="WdatePicker({Date:'%y-%M-{%d}'})" /> 至 

                                                              <input runat="server" readonly="readonly" id="EdDate" onfocus="WdatePicker({Date:'%y-%M-{%d}'})" />

                                                        </td>

                                                    </tr>

                                                    <tr>

                                                        <td class="BDTD">

                                                            打印状态</td>

                                                        <td class="WHITETD">

                                                            <asp:DropDownList ID="ddlPrintStatus" runat="server">

                                                                <asp:ListItem Value="">全部记录</asp:ListItem>

                                                                <asp:ListItem Value="1">已打印</asp:ListItem>

                                                                <asp:ListItem Selected="True" Value="0">未打印</asp:ListItem>

                                                            </asp:DropDownList>

                                                        </td>

                                                        <td class="BDTD">

                                                             </td>

                                                        <td class="WHITETD">

                                                             </td>

                                                    </tr>

                                                    

                                                  <%--  <tr>

                                                        <td class="BDTD" width="15%">

                                                            学员编号</td>

                                                        <td class="WHITETD" width="35%">

                                                            <asp:TextBox ID="txtS_No" runat="server" Width="160px"></asp:TextBox></td>

                                                        <td class="BDTD" width="15%">

                                                            学员姓名</td>

                                                        <td class="WHITETD" width="35%">

                                                            <asp:TextBox ID="txtS_Name" runat="server" Width="100px"></asp:TextBox></td>

                                                    </tr>--%>

                                                  <%--  <tr>

                                                        <td class="BDTD">

                                                            审批状态</td>

                                                        <td class="WHITETD">

                                                            <asp:DropDownList id="ddlAuditStatus" runat="server">

																    <asp:ListItem Selected="True"> </asp:ListItem>

                                                                    <asp:ListItem>通过</asp:ListItem>

                                                                    <asp:ListItem>未通过</asp:ListItem>

                                                                    <asp:ListItem>未审核</asp:ListItem>

																</asp:DropDownList>

														</td>

                                                        <td class="BDTD">

                                                            批量编号</td>

                                                        <td class="WHITETD">

                                                            <asp:DropDownList ID="ddlS_Batch" runat="server" Enabled="false">

                                                            </asp:DropDownList></td>

                                                    </tr>--%>

                                                  <%--  <tr>

                                                        <td class="BDTD">

                                                            证件类型</td>

                                                        <td class="WHITETD">

                                                            <asp:DropDownList ID="ddlPaType" runat="server">

                                                            </asp:DropDownList>

                                                        </td>

                                                       

                                                    </tr>--%>

                                                  <%--  <tr>

                                                        <td class="BDTD">

                                                            学员状态</td>

                                                        <td class="WHITETD">

                                                            <asp:DropDownList ID="ddlS_Status" runat="server">

                                                            </asp:DropDownList>

                                                        </td>

                                                        <td class="BDTD">

                                                            学车类型</td>

                                                        <td class="WHITETD">

                                                            <asp:DropDownList ID="ddlS_StudyVehicleType" runat="server">

                                                                <asp:ListItem Value=" "></asp:ListItem>

                                                            </asp:DropDownList>

                                                        </td>

                                                    </tr>--%>

                                                    <tr bgcolor="#cccccc">

                                                        <td align="center" colspan="4" height="30">

                                                            <asp:Button ID="Button1" runat="server" Width="60PX" Text="搜索" Height="22px" Font-Size="12px"

                                                                OnClick="Button1_Click"></asp:Button>

<%--                                                             <asp:Button ID="Button5" runat="server" Font-Size="12px" Height="22px" 

                                                                Text="导出" Width="60PX" onclick="Button5_Click" />--%>

                                                              </td>

                                                    </tr>

                                                    <tr>

                                                        <td colspan="4" height="30" >

                                                             <input id="btnPrint" runat="server" type="button" onclick="PrintUrl();" value="批量打印" style="float:right;" />

                                                        </td>

                                                    </tr>

                                                </table>

                                            </td>

                                        </tr>

                                    </table>

                                </asp:Panel>

<%--                                <asp:Panel ID="pAudit" Width="100%" runat="server">

                                    <table align="center" border="0" cellpadding="0" cellspacing="0" width="100%">                                        

										<tr bgcolor="#cccccc">                                                    

                                            <td align="right" height="25px">

                                                审批操作: <asp:DropDownList ID="ddlAudit" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlAudit_SelectedIndexChanged">

                                                   <asp:ListItem Selected="True"> </asp:ListItem>

                                                   <asp:ListItem>通过</asp:ListItem>

                                                   <asp:ListItem>未通过</asp:ListItem>

                                               </asp:DropDownList> 

                                            </td>

                                        </tr>

                                    </table>

                                </asp:Panel>--%>

                                <asp:Panel ID="ResultPanel" runat="server" Width="100%">

                                    <table cellspacing="1" cellpadding="1" width="100%" align="center" border="0">

                                        <tr>

                                            <td align="center">

                                                <asp:DataGrid ID="DataGrid1" runat="Server" Width="100%" 

                                                    BorderColor="#006D4A" BorderWidth="1px" PageSize="15" 

                                                    AutoGenerateColumns="False" OnItemDataBound="DataGrid1_ItemDataBound" >

                                                    <AlternatingItemStyle BackColor="#F7F7F7"></AlternatingItemStyle>

                                                    <ItemStyle HorizontalAlign="Center" Height="20px"></ItemStyle>

                                                    <HeaderStyle HorizontalAlign="Center" Height="22px" ForeColor="White" VerticalAlign="Middle"

                                                        BackColor="#006D4A"></HeaderStyle>

                                                    <Columns>

                                                        <asp:TemplateColumn HeaderText="序号" ItemStyle-Width="6%">

                                                            <ItemTemplate><%# Container.ItemIndex + 1%></ItemTemplate>

                                                        </asp:TemplateColumn>

                                                        <asp:BoundColumn DataField="D_Name" HeaderText=" 所属驾校" ItemStyle-Width="7%"></asp:BoundColumn>

                                                     <%--   <asp:BoundColumn DataField="RS_Name" HeaderText="招生点" ItemStyle-Width="7%" Visible="False"></asp:BoundColumn>--%>

                                                      <%--  <asp:BoundColumn DataField="S_No" HeaderText="学员编号" ItemStyle-Width="7%"></asp:BoundColumn>--%>

                                                        <asp:BoundColumn DataField="S_Name" HeaderText="学员姓名" ItemStyle-Width="7%"></asp:BoundColumn>

                                                   <%--     <asp:BoundColumn DataField="S_PaType" HeaderText="证件类型" ItemStyle-Width="7%"></asp:BoundColumn>--%>

                                                        <asp:BoundColumn DataField="S_IDCardNo" HeaderText="证件号" ItemStyle-Width="7%"></asp:BoundColumn>

                                                        <%--<asp:BoundColumn DataField="S_Tel" HeaderText="联系电话" ItemStyle-Width="7%"></asp:BoundColumn>--%>

                                                        <asp:BoundColumn DataField="S_StudyVehicleType" HeaderText="学车类型" ItemStyle-Width="7%"></asp:BoundColumn>

                                                        <%--<asp:BoundColumn DataField="S_ContractNo" HeaderText="合同编号"></asp:BoundColumn>--%>

                                                        <asp:BoundColumn DataField="S_RegisterDate" HeaderText="报名日期" ItemStyle-Width="7%" DataFormatString="{0:yyyy-MM-dd}" ></asp:BoundColumn>

                                                        <%--<asp:BoundColumn DataField="S_ActiveTime" HeaderText="激活日期" ItemStyle-Width="7%"></asp:BoundColumn>--%>

														<%--<asp:BoundColumn DataField="S_Status" HeaderText="学员状态" ItemStyle-Width="7%"></asp:BoundColumn>--%>

														<%--<asp:BoundColumn DataField="S_Flag" HeaderText="审批状态" ItemStyle-Width="6%"></asp:BoundColumn>--%>

                                                        <%-- <asp:TemplateColumn HeaderText="学习进度" ItemStyle-Width="6%">

                                                            <ItemTemplate>

                                                                <a href='w_studentStudyResultYC.aspx?SNo=<%# (DataBinder.Eval(Container,"DataItem.S_No"))%>'>学习进度</a>

                                                            </ItemTemplate>

                                                        </asp:TemplateColumn>--%>

                                                        

                                                        <asp:TemplateColumn HeaderText="操作" ItemStyle-Width="6%">

                                                            <ItemTemplate>

                                                                <a target="_blank"  style=" color:Blue;"href='CertificatePrint.aspx?ID=<%# (DataBinder.Eval(Container,"DataItem.ID"))%>'>结业证打印</a>

                                                            </ItemTemplate> 

                                                        </asp:TemplateColumn>

                                                                                                             <asp:TemplateColumn HeaderText="选择" ItemStyle-Width="6%" >

                                                            <HeaderTemplate>

                                                                <asp:CheckBox ID="check1" runat="server"

                                                                    onclick="javascript:SelectAll(this);" />

                                                            </HeaderTemplate>

                                                                                                                  <ItemTemplate>

                                                                <asp:Label ID="lbid" runat="server"

                                                                    Text='<%# DataBinder.Eval(Container,"DataItem.ID")%>' Visible="False"></asp:Label>

                                                                                                                               <input id="CheckSingle" type="checkbox" name="<%#DataGrid1.ClientID%>_CheckSingle"  />

                                                            

                                                            </ItemTemplate>

                                                        </asp:TemplateColumn>

                                                    </Columns>

                                                </asp:DataGrid>

                                            </td>

                                        </tr>                                        

										<tr>

                                            <td bgcolor="#CCCCCC" align="right">

                                                <asp:LinkButton ID="lbFirst" runat="server" OnClick="lbFirst_Click" Enabled="false">首页</asp:LinkButton>

                                                <asp:LinkButton ID="lbBack" runat="server" OnClick="lbBack_Click" Enabled="false">上一页</asp:LinkButton>

                                                <asp:LinkButton ID="lbNext" runat="server" OnClick="lbNext_Click" Enabled="false">下一页</asp:LinkButton>

                                                <asp:LinkButton ID="lbLast" runat="server" OnClick="lbLast_Click" Enabled="false">末页</asp:LinkButton>  

                                                第<asp:DropDownList ID="ddlPageSelect" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlPageSelect_SelectedIndexChanged">

                                                    <asp:ListItem Value="1">1/1</asp:ListItem>

                                                </asp:DropDownList>页  

                                                共有<asp:Label ID="lbTotal" runat="server"></asp:Label>个记录  

                                                每页<input id="tbPageSize" runat="server" style="width:35px;" value="15" />个记录

                                            </td>

                                        </tr>

                                    </table>

                                </asp:Panel>

                            </td>

                        </tr>

                    </table>

                </td>

            </tr>

        </table>

    </form>

</body>

</html>

 2、打印页面(前台)

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CertificatePrint.aspx.cs" Inherits="DTMIS.Web.StudentMG.CertificatePrint" %>



<!DOCTYPE html>



<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <meta http-equiv="X-UA-Compatible" content="IE=8" />

    <title></title>

    <script src="../js/jquery-1.7.2.min.js"></script>

    <script src="../js/LodopFuncs.js"></script>

    <object id="LODOP_OB" classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width="0"

        height="0">

        <embed id="LODOP_EM" type="application/x-print-lodop" width="0" height="0" pluginspage="install_lodop.exe"></embed>

    </object>

    <script>

        function ClosePrintPage() {

            window.opener = null;

            window.open('', '_self', '');

            window.close();

        }

        var LODOP; //声明为全局变量

        function showPrint() {

            var stuid = '<%=iStudentID%>';

            CreatePage();



            LODOP.SET_SHOW_MODE("BKIMG_IN_PREVIEW", 1); //注:"BKIMG_IN_PREVIEW"-预览包含背景图 "BKIMG_IN_FIRSTPAGE"- 仅首页包含背景图		

            LODOP.SET_SHOW_MODE("HIDE_SBUTTIN_PREVIEW", 1);

            var printCount = LODOP.PREVIEW();

            //LODOP.PRINT_DESIGN();

            if (printCount > 0) {

                //DTMIS.Web.StudentMG.w_studentGradPa.UpdatePrintStatus();

                $.ajax({

                    type: "post",

                    url: "CertificatePrint.aspx/UpdatePrintStatus",

                    dataType: "json",

                    data: "{'stuid':" + stuid + "}",

                    contentType: "application/json;charsert=utf-8;",

                    success: function (data) {

                    }

                });

            }

            ClosePrintPage();

        }

        function CreatePage() {



            LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));

            LODOP.SET_PRINT_MODE("PRINT_PAGE_PERCENT", "100%");//

            //LODOP.PRINT_INITA(0, 0, 3800, 3600, "廊坊驾培结业证书打印");//参数说明:(距上,距左,打印区宽度,打印区高度)

            LODOP.PRINT_INITA(0, 0, 1123, 756, "廊坊驾培结业证书打印");

            LODOP.SET_PRINT_PAGESIZE(1, 1850, 2680, "A4");

            LODOP.SET_SHOW_MODE("HIDE_PAPER_BOARD", 1);   //隐藏背景条文

            LODOP.SET_SHOW_MODE("HIDE_SBUTTIN_PREVIEW", 1);

            LODOP.SET_SHOW_MODE("LANDSCAPE_DEFROTATED", 1); //注:"BKIMG_IN_PREVIEW"-预览包含背景图 "BKIMG_IN_FIRSTPAGE"- 仅首页包含背景图		



            //LODOP.ADD_PRINT_IMAGE(8, 15, 2000, 1760, "<img border='0' src='../Images/001.jpg' />");//设置背景图片

            LODOP.ADD_PRINT_TEXT(85, 70, 280, 50, "<%=S_GraduateNo %>");//证件编号

            LODOP.SET_PRINT_STYLEA(0, "FontSize", 16);

            LODOP.SET_PRINT_STYLEA(0, "Bold", 1);

            LODOP.SET_PRINT_STYLEA(0, "FontName", "楷体");





            //LODOP.ADD_PRINT_IMAGE(100, 400, 132, 185, "<img border='0' src='<%= S_Pic%>' />");//照片

            LODOP.ADD_PRINT_TEXT(165, 55, 200, 50, "<%=S_Name %>");//学员名称

            LODOP.SET_PRINT_STYLEA(0, "FontSize", 16);

            LODOP.SET_PRINT_STYLEA(0, "Bold", 1);

            LODOP.SET_PRINT_STYLEA(0, "FontName", "楷体");





            LODOP.ADD_PRINT_TEXT(165, 165, 100, 50, "<%=S_Sex %>");//性别

            LODOP.SET_PRINT_STYLEA(0, "FontSize", 16);

            LODOP.SET_PRINT_STYLEA(0, "Bold", 1);

            LODOP.SET_PRINT_STYLEA(0, "FontName", "楷体");





            LODOP.ADD_PRINT_TEXT(190, 245, 100, 50, "<%=S_StudyVehicleType %>");//准驾车型

            LODOP.SET_PRINT_STYLEA(0, "FontSize", 16);

            LODOP.SET_PRINT_STYLEA(0, "Bold", 1);

            LODOP.SET_PRINT_STYLEA(0, "FontName", "楷体");





            LODOP.ADD_PRINT_TEXT(165, 230, 100, 50, "<%=sRegYear %>");//报名时间(年)

            LODOP.SET_PRINT_STYLEA(0, "FontSize", 16);

            LODOP.SET_PRINT_STYLEA(0, "Bold", 1);

            LODOP.SET_PRINT_STYLEA(0, "FontName", "楷体");





            LODOP.ADD_PRINT_TEXT(165, 310, 100, 50, "<%=sRegMonth %>");//报名时间(月)

            LODOP.SET_PRINT_STYLEA(0, "FontSize", 16);

            LODOP.SET_PRINT_STYLEA(0, "Bold", 1);

            LODOP.SET_PRINT_STYLEA(0, "FontName", "楷体");





            LODOP.ADD_PRINT_TEXT(165, 350, 100, 50, "<%=sRegDay %>");//报名时间(日)

            LODOP.SET_PRINT_STYLEA(0, "FontSize", 16);

            LODOP.SET_PRINT_STYLEA(0, "Bold", 1);

            LODOP.SET_PRINT_STYLEA(0, "FontName", "楷体");





            LODOP.ADD_PRINT_TEXT(190, 15, 100, 50, "<%=gRYear %>");//结业时间(年)

            LODOP.SET_PRINT_STYLEA(0, "FontSize", 16);

            LODOP.SET_PRINT_STYLEA(0, "Bold", 1);

            LODOP.SET_PRINT_STYLEA(0, "FontName", "楷体");





            LODOP.ADD_PRINT_TEXT(190, 88, 100, 50, "<%=gRMonth %>");//结业时间(月)

            LODOP.SET_PRINT_STYLEA(0, "FontSize", 16);

            LODOP.SET_PRINT_STYLEA(0, "Bold", 1);

            LODOP.SET_PRINT_STYLEA(0, "FontName", "楷体");



            LODOP.ADD_PRINT_TEXT(190, 130, 100, 50, "<%=gRDay %>");//结业时间(日)

            LODOP.SET_PRINT_STYLEA(0, "FontSize", 16);

            LODOP.SET_PRINT_STYLEA(0, "Bold", 1);

            LODOP.SET_PRINT_STYLEA(0, "FontName", "楷体");



            LODOP.ADD_PRINT_TEXT(240, 245, 500, 50, "<%=D_Name %>");//培训机构

            LODOP.SET_PRINT_STYLEA(0, "FontSize", 16);

            LODOP.SET_PRINT_STYLEA(0, "Bold", 1);

            LODOP.SET_PRINT_STYLEA(0, "FontName", "楷体");





            LODOP.ADD_PRINT_TEXT(265, 215, 100, 50, "<%=sPrintYear %>");//打印时间(年)

            LODOP.SET_PRINT_STYLEA(0, "FontSize", 12);

            LODOP.SET_PRINT_STYLEA(0, "Bold", 1);

            LODOP.SET_PRINT_STYLEA(0, "FontName", "楷体");



            LODOP.ADD_PRINT_TEXT(265, 295, 100, 50, "<%=sPrintMonth %>");//打印时间(月)

            LODOP.SET_PRINT_STYLEA(0, "FontSize", 12);

            LODOP.SET_PRINT_STYLEA(0, "Bold", 1);

            LODOP.SET_PRINT_STYLEA(0, "FontName", "楷体");



            LODOP.ADD_PRINT_TEXT(265, 348, 100, 50, "<%=sPrintDay %>");//打印时间(日)

            LODOP.SET_PRINT_STYLEA(0, "FontSize", 12);

            LODOP.SET_PRINT_STYLEA(0, "Bold", 1);

            LODOP.SET_PRINT_STYLEA(0, "FontName", "楷体");

}







    </script>

</head>

<body onload="showPrint()">

    <form id="form1" style="margin: 0px; padding: 0px; text-align: left;" runat="server">

        <div id="div_PrintDown">

            <input type="button" value="打印预览" name="B3" onclick="showPrint()" />

        </div>



    </form>

</body>

</html>

 3、后台代码

using AjaxPro;

using DTMIS.BLL;

using System;

using System.Collections.Generic;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Services;

using System.Web.UI;

using System.Web.UI.WebControls;



namespace DTMIS.Web.StudentMG

{

    public partial class CertificatePrint : System.Web.UI.Page

    {

       

        private string ModuleDir = "StudentMG/";

        private string ModulePage = "CertificatePrint.aspx";

        public static int iStudentID;//学员编号

        public string S_GraduateNo;//资格证号

        public string S_Name;//姓名

        public string S_Sex;//性别

        public DateTime S_RegisterDate;//报名日期

        public string S_Pic;//照片

        public string S_StudyVehicleType;//准驾车型

        public string D_Name;//驾校

        protected string sRegYear;

        protected string sRegMonth;

        protected string sRegDay;



        protected string gRYear;

        protected string gRMonth;

        protected string gRDay;



        protected string sPrintYear;

        protected string sPrintMonth;

        protected string sPrintDay;

        protected void Page_Load(object sender, EventArgs e)

        {

            //if (!Common.canAccess(this.ModuleDir + this.ModulePage))

            //{

            //    base.Response.Redirect("../NoPower.html");

            //} 

            if (!IsPostBack)

            {

                Utility.RegisterTypeForAjax(typeof(CertificatePrint));

                iStudentID = Convert.ToInt32(base.Request.QueryString["ID"]);



                DataSet set = BLL.T_Student_Base.getStudentData(iStudentID);



                if (set.Tables.Count > 0)

                {

                    foreach (DataRow item in set.Tables[0].Rows)

                    {

                        DateTime time;

                        DateTime time1;

                        S_GraduateNo = item["S_GraduateNo"].ToString().Trim();

                        S_Name = item["S_Name"].ToString().Trim();

                        S_Sex = item["S_Sex"].ToString().Trim();

                        S_Pic = ConvertUrl(item["S_Pic"].ToString().Trim());

                        S_StudyVehicleType = item["S_StudyVehicleType"].ToString().Trim();

                        D_Name = item["D_Name"].ToString().Trim();

                        //报名日期

                        if (item["S_RegisterDate"].ToString() != "")

                        {

                            time = Convert.ToDateTime(item["S_RegisterDate"].ToString());

                            sRegYear = time.Year.ToString();

                            sRegMonth = time.Month.ToString();

                            sRegDay = time.Day.ToString();

                        }

                        //结业日期

                        if (item["A_AddTime"].ToString() != "")

                        {

                            time1 = Convert.ToDateTime(item["A_AddTime"].ToString());

                            gRYear = time1.Year.ToString();

                            gRMonth = time1.Month.ToString();

                            gRDay = time1.Day.ToString();

                        }

                        //打印时间

                        DateTime now = DateTime.Now;

                        sPrintYear = now.Year.ToString();

                        sPrintMonth = now.Month.ToString();

                        sPrintDay = now.Day.ToString();

                    }





                }



            }

        }

        //[AjaxMethod]

        [WebMethod]

        public static string UpdatePrintStatus(string stuid)

        {

            string msg = string.Empty;

            int result = Common.Update("T_Student_Base", "IsGraducatePrint=1", "ID=" + stuid);

            if (result > 0)

            {

                msg = "ok";

            }

            else

            {

                msg = "error";

            }

            return msg;



        }

        private string ConvertUrl(string imgUrl)

        {

            if (!string.IsNullOrEmpty(imgUrl))

            {

                imgUrl = imgUrl.Substring(1, imgUrl.Length - 1);

                string strDomain = "http://" + HttpContext.Current.Request.Url.Host;

                int iPort = HttpContext.Current.Request.Url.Port;

                string imgPath = strDomain + ":" + iPort.ToString() + "/" +

                                 imgUrl.Replace(Server.MapPath("/"), "").Replace(@"\", "/");



                return imgPath;

            }

            else

            {

                return "";

            }

        }

    }

}

 以上三步即可实现lodop打印

你可能感兴趣的:(asp.net)