Sunday 1 January 2012

Complete code For HtmlReport

Default.aspx(Design)-:


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














Default.aspx.cs(Code):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Data;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
Button bt;
protected void Page_Load(object sender, EventArgs e)
{
bt = new Button();
bt.ID = "SS";
bt.Text = "Word";
bt.Attributes.Add("style", "font-weight:bold");
bt.Click+=new EventHandler(bt_Click);
form1.Controls.Add(bt);

DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("~/App_Data/XMLFile.xml"));

StringBuilder strHtmlContent = new StringBuilder();
strHtmlContent.Append("

Student Information

".ToString());
strHtmlContent.Append("
".ToString());
strHtmlContent.Append("".ToString()); strHtmlContent.Append("".ToString()); strHtmlContent.Append("".ToString()); strHtmlContent.Append("".ToString()); strHtmlContent.Append("
College Name:A.S COLLEGE,TIRTOLDate:30/12/2011fghjkl
College Address:Tirtol,JagatsinfhpurPlace:Tirtol
Year:2011
".ToString());
strHtmlContent.Append("".ToString()); strHtmlContent.Append("".ToString()); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { strHtmlContent.Append("".ToString()); } strHtmlContent.Append("
NameCountryCity
" + ds.Tables[0].Rows[i][0].ToString() + "" + ds.Tables[0].Rows[i][1].ToString() + "" + ds.Tables[0].Rows[i][2].ToString() + "
".ToString());
strHtmlContent.Append("".ToString()); strHtmlContent.Append("".ToString()); strHtmlContent.Append("".ToString()); strHtmlContent.Append("".ToString()); strHtmlContent.Append("
Signture:
Date:
   
".ToString());
LblView.Text = strHtmlContent.ToString();
}
protected void btnword_Click(object sender, EventArgs e)
{
Response.Write("Hi.............");
}
protected void bt_Click(object sender, EventArgs e)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Charset = "";
HttpContext.Current.Response.ContentType = "application/msword";
string Filename = "ExportWord" + ".doc";
HttpContext.Current.Response.AddHeader("Content-Disposition", "inline;filename=" + Filename);

HttpContext.Current.Response.Write(LblView.Text);
HttpContext.Current.Response.End();
HttpContext.Current.Response.Flush();
}

}

No comments:

Post a Comment