Click here to Skip to main content
15,886,055 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: Repeat table onclick Pin
Not Active29-Aug-11 9:02
mentorNot Active29-Aug-11 9:02 
Questionhow to put condition under the table which is inside the repeater?? Pin
Dhyanga23-Aug-11 12:05
Dhyanga23-Aug-11 12:05 
AnswerRe: how to put condition under the table which is inside the repeater?? Pin
Not Active23-Aug-11 12:21
mentorNot Active23-Aug-11 12:21 
GeneralRe: how to put condition under the table which is inside the repeater?? Pin
Dhyanga23-Aug-11 12:49
Dhyanga23-Aug-11 12:49 
GeneralRe: how to put condition under the table which is inside the repeater?? Pin
Not Active23-Aug-11 13:06
mentorNot Active23-Aug-11 13:06 
GeneralRe: how to put condition under the table which is inside the repeater?? Pin
Dhyanga23-Aug-11 13:16
Dhyanga23-Aug-11 13:16 
GeneralRe: how to put condition under the table which is inside the repeater?? Pin
Not Active23-Aug-11 13:38
mentorNot Active23-Aug-11 13:38 
GeneralRe: how to put condition under the table which is inside the repeater?? Pin
Dhyanga23-Aug-11 16:42
Dhyanga23-Aug-11 16:42 
Ok. I have database something like this: For pdf I have used iTextSharp 4.2.1.0 version. pdf part is working fine but pdf page break is where I got problem.
table one is
CustomerOrder
--------------
FirstName
LastName
GroupName
Email
CreationDate


second table is
OrderItem
------------
ID
OrderID
Item
ItemDescription
Category
Amount
CustomerID
IsActive


Now my design page is like this:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MainPage.aspx.cs" Inherits="iTextSharpExample._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>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:Button ID="pdfReportFromDatabase" runat="server" onclick="pdfReportFromDatabase_Click" Text="Button" />
    <div>
    
    </div>
    <asp:Repeater runat="server" ID="cusDptInfo" onitemdatabound="cusDptInfo_ItemDataBound" >
    <ItemTemplate ><font size="60%">
    <%# DataBinder.Eval(Container.DataItem, "FirstName") %> <%# DataBinder.Eval(Container.DataItem, "LastName") %><br />
    <%# DataBinder.Eval(Container.DataItem, "GroupName") %><br />
    <%# DataBinder.Eval(Container.DataItem, "Email") %><br />
    <%# DataBinder.Eval(Container.DataItem, "CreationDate","{0:MM/dd/yyyy}") %><br />   
    <br /></font>
        <asp:Repeater ID="rptItemList" runat="server">
            <ItemTemplate>
                <asp:Table ID="tblItemList" runat="server" Font-Size="7%">
                    <asp:TableRow>
                        <asp:TableCell><%# DataBinder.Eval(Container.DataItem,"Item")%> <%#DataBinder.Eval(Container.DataItem, "Category","({0})")%><br /><font color="gray" style="text-align:justify"><%# DataBinder.Eval(Container.DataItem, "ItemDescription") %></font></asp:TableCell>
                        <asp:TableCell HorizontalAlign="Right"><%# DataBinder.Eval(Container.DataItem,"Amount","{0:c}") %></asp:TableCell>
                    </asp:TableRow>
                </asp:Table>
            </ItemTemplate>
        </asp:Repeater>
        <asp:Repeater ID="rptOrderedTotAmount" runat="server">
            <ItemTemplate>  <div style="page-break-after:always;">         
                <asp:Table ID="tblItemListt" runat="server" Font-Size="7%">
                    <asp:TableRow>
                        <asp:TableCell HorizontalAlign="Right"><%# DataBinder.Eval(Container.DataItem, "TotalAmount","Total: {0:c}") %></asp:TableCell>
                     </asp:TableRow>
                </asp:Table> </div>
                <br />
            </ItemTemplate>
        </asp:Repeater>
    </ItemTemplate>
</asp:Repeater>
    </form>
    </body>
</html>


and my code behind is like this:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using System.Data.OleDb;


using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;
using iTextSharp.text.html.simpleparser;

namespace iTextSharpExample
{
    public partial class _Default : System.Web.UI.Page
    {
        public static string strCnx = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=g:\\access\\CustomerOrderDetails.mdb;Jet OLEDB:System Database=g:\\access\\system.mdw;" 
;


        #region Properties
        Repeater rptItemList;
        Repeater rptOrderedTotAmount;
        #endregion
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void filetesting()
        {

            OleDbConnection cnx = new OleDbConnection(strCnx);
            DataSet ds = new DataSet();

            string catQuery = @"select * from CustomerOrder";
            OleDbCommand objCmd = new OleDbCommand(catQuery, cnx);
            OleDbDataAdapter objDAcategory = new OleDbDataAdapter(objCmd);
            objDAcategory.Fill(ds, "CustomerOrder");

            string totQuery = @"select OrderID,sum(Amount) As [TotalAmount] from OrderedItem where IsActive = '1' group by OrderID";
            objCmd = new OleDbCommand(totQuery, cnx);
            OleDbDataAdapter objDAtotal = new OleDbDataAdapter(objCmd);
            objDAtotal.Fill(ds, "OrderedItem");

            string itemQuery = @"select * from OrderedItem where IsActive='1'";
            objCmd = new OleDbCommand(itemQuery, cnx);
            OleDbDataAdapter objDAitem = new OleDbDataAdapter(objCmd);
            objDAitem.Fill(ds, "OrderedItem");

            DataRelation dRel = new DataRelation("CustomerOrder_OrderedItem", ds.Tables["CustomerOrder"].Columns["OrderID"], ds.Tables["OrderedItem"].Columns["OrderID"]);
            ds.Relations.Add(dRel);
            cusDptInfo.DataSource = ds;
            cusDptInfo.DataBind();

            HttpContext.Current.Response.Clear(); //clear anything in io buffer           
            HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=iTextSharpExample.pdf");
            HttpContext.Current.Response.Charset = "";
            HttpContext.Current.Response.ContentType = "application/pdf";
            StringWriter stringwrite = new StringWriter();
            HtmlTextWriter htmlwrite = new HtmlTextWriter(stringwrite);
            cusDptInfo.RenderControl(htmlwrite);
            StringReader sr = new StringReader(stringwrite.ToString());
            Document pdfDoc = new Document(PageSize.A4, 50f, 50f, 40f, 40f);
            PdfWriter writer = PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
            HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
            string pcnt;
            pcnt = (writer.CurrentPageNumber - 1).ToString();
            pcnt = pcnt.Substring(1);
            HeaderFooter header = new HeaderFooter(new Phrase("My Company \n Customer Order Details"), false) { Border = Rectangle.NO_BORDER, Alignment = Element.ALIGN_CENTER };
            HeaderFooter footer = new HeaderFooter(new Phrase(pcnt), true) { Border = Rectangle.NO_BORDER, Alignment = Element.ALIGN_CENTER };
            pdfDoc.Header = header;
            pdfDoc.Footer = footer;
            pdfDoc.Open();
            _events e = new _events();

            e.TimerText = DateTime.Now.ToString("MM/dd/yyyy");

            writer.PageEvent = e;

            htmlparser.Parse(sr);
            pdfDoc.NewPage();
            pdfDoc.Close();


            Response.Write(pdfDoc);


        }

        protected void cusDptInfo_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
       
            RepeaterItem item = e.Item;
            if ((item.ItemType == ListItemType.Item) ||
                (item.ItemType == ListItemType.AlternatingItem))
            {
                rptItemList = (Repeater)e.Item.FindControl("rptItemList");
                DataRowView drv = (DataRowView)item.DataItem;
                rptItemList.DataSource = drv.CreateChildView("CustomerOrder_OrderedItem");
                rptItemList.DataBind();

                rptOrderedTotAmount = (Repeater)e.Item.FindControl("rptOrderedTotAmount");
                DataRowView drvTot = (DataRowView)item.DataItem;
                rptOrderedTotAmount.DataSource = drvTot.CreateChildView("CustomerOrder_OrderedItem");
                rptOrderedTotAmount.DataBind();

            }
       
        }

        protected void pdfReportFromDatabase_Click(object sender, EventArgs e)
        {
            filetesting();
        }
    }

    public class _events : PdfPageEventHelper
    {
        private string _timerText;

        public string TimerText
        {
            get { return _timerText; }
            set { _timerText = value; }
        }

        public override void OnEndPage(PdfWriter writer, Document document)
        {
            base.OnEndPage(writer, document);
            Rectangle page = document.PageSize;
            ColumnText.ShowTextAligned(writer.DirectContent, Element.ALIGN_RIGHT, new Phrase(TimerText), page.Right, page.Height - document.TopMargin, 0);

        }

    }
}


ok I need to page break once i get my TotalAmount. I had used style=page-break-after:always property under the nested repeater as shown. Its working for part of data and for part of data, its not working. Page break is happening for some part and for some part there is no page break. This is my problem. I need page break throughout my data.
suchita

GeneralRe: how to put condition under the table which is inside the repeater?? Pin
Not Active23-Aug-11 17:02
mentorNot Active23-Aug-11 17:02 
GeneralRe: how to put condition under the table which is inside the repeater?? Pin
Dhyanga24-Aug-11 2:57
Dhyanga24-Aug-11 2:57 
GeneralRe: how to put condition under the table which is inside the repeater?? Pin
Dhyanga29-Aug-11 10:38
Dhyanga29-Aug-11 10:38 
Questionasp Pin
royaizadi23-Aug-11 8:19
royaizadi23-Aug-11 8:19 
AnswerRe: asp Pin
Not Active23-Aug-11 8:27
mentorNot Active23-Aug-11 8:27 
JokeRe: asp Pin
Manfred Rudolf Bihy23-Aug-11 8:50
professionalManfred Rudolf Bihy23-Aug-11 8:50 
GeneralRe: asp Pin
Not Active23-Aug-11 9:02
mentorNot Active23-Aug-11 9:02 
GeneralRe: asp Pin
S Douglas23-Aug-11 14:39
professionalS Douglas23-Aug-11 14:39 
GeneralRe: asp Pin
Manfred Rudolf Bihy24-Aug-11 3:42
professionalManfred Rudolf Bihy24-Aug-11 3:42 
GeneralRe: asp Pin
S Douglas24-Aug-11 4:29
professionalS Douglas24-Aug-11 4:29 
GeneralRe: asp Pin
Manfred Rudolf Bihy24-Aug-11 3:39
professionalManfred Rudolf Bihy24-Aug-11 3:39 
GeneralRe: asp Pin
Not Active24-Aug-11 4:21
mentorNot Active24-Aug-11 4:21 
GeneralRe: asp Pin
Manfred Rudolf Bihy24-Aug-11 3:46
professionalManfred Rudolf Bihy24-Aug-11 3:46 
GeneralRe: asp Pin
Not Active24-Aug-11 4:19
mentorNot Active24-Aug-11 4:19 
QuestionStore files temporarily Pin
SummerBulb22-Aug-11 6:48
SummerBulb22-Aug-11 6:48 
AnswerRe: Store files temporarily Pin
GenJerDan22-Aug-11 7:04
GenJerDan22-Aug-11 7:04 
AnswerRe: Store files temporarily Pin
David Mujica22-Aug-11 7:41
David Mujica22-Aug-11 7:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.