Click here to Skip to main content
15,896,111 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        M_setHtml();
     // GenerateMsWordDoc();
    }

    private void M_setHtml()
    {
        String _mainhtml = String.Empty;
        String _htmlhead = String.Empty;
        String _htmlfooter = String.Empty;

        String _html = String.Empty;
        ArrayList arrValues = new ArrayList(4);

        Int32 _index = 1;
        for (int i = 0; i < 2; i++)
        {
            //arrValues.Add(i.ToString());
          // _mainhtml = "";
            _htmlhead = "";
            _html = "";
            _htmlfooter = "";
            _index = 1;
            _htmlhead += "<table width='100%'  >";
            _htmlhead += "<tr> <td colspan='3'><b> Demo Doc</b></td></tr>";
            _htmlhead += "<tr> <td>Head 1</td> <td>Head 2</td> <td>Head 3</td></tr>";
            _htmlhead += "<tr> <td valign='top'>Tajuk Kurus</td> <td valign='top' colspan='2' >Tajuk Kurus</td> </tr>";
            _htmlhead += "<tr><td valign='top'>Tarkish</td> <td valign='top' colspan='2' >Tarkish</td> </tr>";
            _htmlhead += "<tr> <td colspan='3' ></td></tr>";
            _htmlhead += "<tr> <td colspan='3' ><table width='100%'> ";


            _htmlfooter += "<tr> <td colspan='3'><b> Footer Doc</b></td></tr>";
            _htmlfooter += "<tr> <td>Head 1</td> <td>Footer 2</td> <td>Footer 3</td></tr>";
            _htmlfooter += "<tr> <td valign='top'>Footer Kurus</td> <td valign='top' colspan='2' >Tajuk Kurus</td> </tr>";
            _htmlfooter += "<tr><td valign='top'>Footer</td> <td valign='top' colspan='2' >Footer</td> </tr>";
            _htmlfooter += "<tr> <td colspan='3' ></td></tr>";
            _htmlfooter += "<tr> <td colspan='3' ></td></tr>";
            _htmlfooter += "<tr> <td colspan='3' ></td></tr>";



            for (int j = 0; j < 25; j++)
            {

                if (_index > 10)
                {
                    _mainhtml += _htmlhead + _html + "</table> </td></tr> " + _htmlfooter+"</table>";
                    _index = 0;
                    _html = "";
                }
                else
                {
                    _html += "<tr><td>" + _index.ToString() + "</td><td>Demo1</td><td>Demo 3</td><td>Demo 4</td></tr>";
                }
                _index = _index + 1;
            }



            if (_index < 10)
            {
                for (int j = 0; j < _index + 3; j++)
                {
                    _html += "<tr><td>--</td><td>Demo1</td><td>Demo 3</td><td>Demo 4</td></tr>";
                    //_index = _index + 1;
                }
                _mainhtml += _htmlhead + _html + "</table> </td></tr>" + _htmlfooter+"</table>";
            }

            tdmain.InnerHtml = _mainhtml;

        }


        // outerdt.DataSource = arrValues;
        //outerdt.DataBind();
        //for (int i = 0; i < 15; i++)
        //{
        //    _html += "<tr><td>" + i.ToString() + "</td><td>Demo1</td><td>Demo 3</td><td>Demo 4</td></tr>";
        //}
        //tdmain.InnerHtml ="<table width='100%'>"+ _html+"</table>";

    }
    protected void outerRep_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        ArrayList arrValues = new ArrayList(4);
        for (int i = 0; i < 15; i++)
        {
            arrValues.Add(i.ToString());
        }
        if (e.Item.ItemType == ListItemType.Item)
        {
            DataRowView drv = e.Item.DataItem as DataRowView;
            DataList innerDataList = e.Item.FindControl("innerDataList") as DataList;
            innerDataList.DataSource = arrValues;
            innerDataList.DataBind();
        }
    }


    protected void GenerateMsWordDoc()
    {

        //String strBody = tdmain.InnerHtml;

        String fileName = "MsWordSample.doc";

        // You can add whatever you want to add as the HTML and it will be generated as Ms Word docs

        Response.AppendHeader("Content-Type", "application/msword");

        Response.AppendHeader("Content-disposition", "attachment; filename=" + fileName);

        Response.Write("");

    }

    protected void btnsend_Click(object sender, EventArgs e)
    {
       // String strBody = divReport.InnerHtml;
        //GenerateMsWordDoc();
    }

}
Posted
Updated 3-Oct-12 1:52am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900