加载预定义的字母模板并填充数据 [英] Loading a pre-defined letter template and populating data

查看:133
本文介绍了加载预定义的字母模板并填充数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当新视图加载并填充字母上某些字段的数据(数据来自存储过程)时,我需要加载一个预定义的字母模板(例如从address到address,date等).
感谢您提供任何帮助.

Hi,

I need to load a pre defined letter template when a new view loads and fill data(data comes from a stored procedure) for some fields on the letter(like from address , to address, date, etc...).
Any kind of help is appreciated.

推荐答案

Hello Donthi
这是针对您的问题的代码示例,但是在C#和ASP.Net中

假设您的模板如下所示
Hello Donthi
Here is the code sample for your problem, but in C# and ASP.Net

suppose your template is as below
<table>
   <tr>
    <td>
      <strong>Dear **FullName**</strong>
    </td>
   </tr>
</table>



在Template.html
文件中 现在,您想在另一页上显示此模板Default.aspx



in the file Template.html
Now you want to show this template on another page Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div runat="server" id="dv">

    </div>
    </form>
</body>
</html>



在页面后面的代码上,编写以下代码



on the code behind page write the following code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace WebApplication1
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
          string filetoread = string.Empty;
          filetoread  = Server.MapPath("~/Template.html");// load the pre   defined letter template
          StreamReader filestream =  (StreamReader)File.OpenText(filetoread);// Load the file into stream
         if (filestream != null)
          {
           string ReadContents = filestream.ReadToEnd();// read the stream from current position to the end of the stream
           filestream.Close();// close stream
           string FinalDoc = ReadContents.Replace("**FullName**", "Rajneesh");//Here you can can sent your own content from Stored Procedure
          }
          dv.InnerText = FinalDoc ;// your template would be loaded into div
        }
    }
}



这只是一个例子.希望能帮助您解决问题.



this is just an example. hope it would help you to solve your problem.


这篇关于加载预定义的字母模板并填充数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆