473,320 Members | 2,164 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Exporting the contebts of repeater to excel.

My problem is ,i have one repeater control.In that the data is binding at BtnGo click.
In that if there are two same vehicle no but they service payments are different ,so after completing the data binding for a partcular vehicle no the total of the payments shud be displayed as a new row named Total.This has to be done for every vehicle.
To get this functionality i used OnItem created event ,and after it was working fine.But Now the problem is this ,that theer is also an option for export to excel.When i use that button,after completing the rendering of the control it only shows the first row and all other values null.
The code i m giving below what i have used:

protected void Content_ItemCreated(object sender, RepeaterItemEventArgs e)
{
string vehicleNo = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "Vehicle No"));



if (e.Item.ItemIndex > 0 && DataVehicleNumber != vehicleNo && (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem))
{
e.Item.Controls.Clear();

TableRow tr = new TableRow();
TableCell tc = new TableCell();
TableCell tc1 = new TableCell();
TableCell tc2 = new TableCell();
TableCell tc3 = new TableCell();
TableCell tc4 = new TableCell();
TableCell tc5 = new TableCell();
TableCell tc6 = new TableCell();
TableCell tc7 = new TableCell();

Label lblnew = new Label();
tc.Controls.Add(lblnew);
lblnew.Text = "<b>Total&nbsp; : &nbsp; </b>" + String.Format("{0:N}",Total);

tc1.Text = "&nbsp;";
tc2.Text = "&nbsp;";
tc3.Text = "&nbsp;";
tc4.Text = "&nbsp;";
tc5.Text = "&nbsp;";
tc6.Text = "&nbsp;";
tc7.Text = "&nbsp;";

tr.Cells.Add(tc1);
tr.Cells[0].CssClass = "datavalue";
tr.Cells.Add(tc2);
tr.Cells[1].CssClass = "datavalue";
tr.Cells.Add(tc3);
tr.Cells[2].CssClass = "datavalue";
tr.Cells.Add(tc4);
tr.Cells[3].CssClass = "datavalue";
tr.Cells.Add(tc5);
tr.Cells[4].CssClass = "datavalue";
tr.Cells.Add(tc6);
tr.Cells[5].CssClass = "datavalue";

tr.Cells.Add(tc);
tr.Cells[6].CssClass = "datavalue";
tr.Cells[6].Attributes.Add("align", "right");

tr.Cells.Add(tc7);
tr.Cells[7].Attributes.Add("bgcolor", "#D8EFFD");
tr.Cells[7].CssClass = "datavalue";

e.Item.Controls.Add(tr);

TableRow Otr = new TableRow();
TableCell Otc0 = new TableCell();
TableCell Otc1 = new TableCell();
TableCell Otc2 = new TableCell();
TableCell Otc3 = new TableCell();
TableCell Otc4 = new TableCell();
TableCell Otc5 = new TableCell();
TableCell Otc6 = new TableCell();
TableCell Otc7 = new TableCell();

Label lblSlno = new Label();
lblSlno.ID = "lblid";
Otc0.Controls.Add(lblSlno);
Otc0.CssClass = "datavalue";
Otr.Cells.Add(Otc0);

Otc1.Text = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "Vehicle No"));
Otc1.CssClass = "datavalue";
Otr.Cells.Add(Otc1);
Otc2.Text = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "Service Type"));
Otc2.CssClass = "datavalue";
Otr.Cells.Add(Otc2);
Otc3.Text = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "Odometer"));
Otc3.CssClass = "datavalue";
Otr.Cells.Add(Otc3);
Otc4.Text = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "Bill No"));
Otc4.CssClass = "datavalue";
Otr.Cells.Add(Otc4);
Otc5.Text = Convert.ToDateTime(DataBinder.Eval(e.Item.DataItem , "Bill Date")).ToString("dd/MM/yyyy");
Otc5.CssClass = "datavalue";
Otr.Cells.Add(Otc5);
Otc6.Text = String.Format("{0:N}",DataBinder.Eval(e.Item.DataI tem, "Amount"));
Otc6.CssClass = "datavalue";
Otc6.Attributes.Add("align", "right");
Otr.Cells.Add(Otc6);

Otc7.Text = "&nbsp;";
Otc7.CssClass = "datavalue";
Otc7.Attributes.Add("bgcolor", "#D8EFFD");
Otr.Cells.Add(Otc7);

e.Item.Controls.Add(Otr);
}

if (e.Item.ItemType == ListItemType.Footer)
{
e.Item.Controls.Clear();

TableRow tr = new TableRow();
TableCell tc = new TableCell();
TableCell tc1 = new TableCell();
TableCell tc2 = new TableCell();
TableCell tc3 = new TableCell();
TableCell tc4 = new TableCell();
TableCell tc5 = new TableCell();
TableCell tc6 = new TableCell();
TableCell tc7 = new TableCell();

Label lblnew = new Label();
tc.Controls.Add(lblnew);
lblnew.Text = "<b>Total&nbsp; : &nbsp; </b>" + String.Format("{0:N}",Total);

tc1.Text = "&nbsp;";
tc2.Text = "&nbsp;";
tc3.Text = "&nbsp;";
tc4.Text = "&nbsp;";
tc5.Text = "&nbsp;";
tc6.Text = "&nbsp;";
tc7.Text = "&nbsp;";

tr.Cells.Add(tc1);
tr.Cells[0].CssClass = "datavalue";
tr.Cells.Add(tc2);
tr.Cells[1].CssClass = "datavalue";
tr.Cells.Add(tc3);
tr.Cells[2].CssClass = "datavalue";
tr.Cells.Add(tc4);
tr.Cells[3].CssClass = "datavalue";
tr.Cells.Add(tc5);
tr.Cells[4].CssClass = "datavalue";
tr.Cells.Add(tc6);
tr.Cells[5].CssClass = "datavalue";

tr.Cells.Add(tc);
tr.Cells[6].CssClass = "datavalue";
tr.Cells[6].Attributes.Add("align", "right");

tr.Cells.Add(tc7);
tr.Cells[7].Attributes.Add("bgcolor", "#D8EFFD");
tr.Cells[7].CssClass = "datavalue";

e.Item.Controls.Add(tr);
}
}



protected void Content_OnItemDataBound(object sender, RepeaterItemEventArgs e)
{
//double totamount;
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
if ((Label)e.Item.FindControl("lblid") != null)
((Label)e.Item.FindControl("lblid")).Text = (e.Item.ItemIndex + 1).ToString();


if (DataVehicleNumber == DataBinder.Eval(e.Item.DataItem, "Vehicle No").ToString())
{
if (((Label)e.Item.FindControl("lblVehicleNumber")) != null)
((Label)e.Item.FindControl("lblVehicleNumber")).Te xt = "&nbsp;";

Total += Convert.ToDouble(DataBinder.Eval(e.Item.DataItem, "Amount"));
//((Label)e.Item.FindControl("lblTotal")).Text = "Total :" + Total.ToString();


//((Label)e.Item.FindControl("lblVehicleNumber")).Te xt = "&nbsp;";
//Total += Convert.ToInt64(DataBinder.Eval(e.Item.DataItem, "Amount"));
//((Label)e.Item.FindControl("lblTotal")).Text = "Total :" + Total.ToString();
}

else
{
Total = 0;
DataVehicleNumber = DataBinder.Eval(e.Item.DataItem, "Vehicle No").ToString();
Total += Convert.ToDouble(DataBinder.Eval(e.Item.DataItem, "Amount"));
// //((Label)e.Item.FindControl("lblTotal")).Text = "Total :" + Total.ToString();

}
}
}
protected void btn_Export_Click(object sender, EventArgs e)
{

Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename=VehicleWiseExpenses.xls") ;
Response.Charset = "";
this.EnableViewState = true;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
Content.RenderControl(oHtmlTextWriter);
Response.Write("User : ");
Response.Write(lblUser.Text);
Response.Write("&nbsp;");
Response.Write("&nbsp;");
Response.Write("&nbsp;");
Response.Write("Run Date : ");
Response.Write(lblrundate.Text);
Response.Write("&nbsp;");
Response.Write("&nbsp;");
Response.Write("&nbsp;");
Response.Write("Time : ");
Response.Write(lblTime.Text);
Response.Write("<br>");
Response.Write("Vehicle Number : ");
Response.Write(lblST.Text);
Response.Write("<br>");
Response.Write("Period : ");
Response.Write(lblPeriod.Text);
Response.Write(oStringWriter.ToString());

Response.End();

}


Please help me out its urgent.
Jul 5 '07 #1
0 1420

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: sridevi | last post by:
Hello How to export data from ms-access database to excel worksheet using ASP. mainly i need to export data to multiple worksheets. it is very urgent to us. i have a sample code which works...
4
by: D | last post by:
I've created a report with many subreports of aggregate data. I want my client to be able to export this data to Excel to make her charts, etc. Only one problem: one of the fields is a "SchoolYear"...
2
by: G | last post by:
When I export data from access to excel by with "export" or "Analyze with" I seem to loose parts of some fields (long text strings). Is there a way to export it all to excel? Thanks G
2
by: Kenneth | last post by:
How do I remove the limitation in Access that deny me from exporting 24000 rows and 17 columns (in a query) into Excel? Kenneth
0
by: Roberto Lopes | last post by:
Hi, I have a dynamic Repeater, where I create some lines in run-time. I need to export this data to an Excel Spreadsheet. I used to do that from a datagrid, but the same solution doesn't work...
2
by: Mustufa Baig | last post by:
Hi everybody, I have an ASP.NET website where clients can view their monthly billings by selecting different options. One of the option is the way they want to see the report i.e. whether they...
1
by: Mustufa Baig | last post by:
I have an ASP.NET website where I am showing off crystal reports to users by exporting them to pdf format. Following is the code: ---------------- 1 Private Sub ExportReport() 2 Dim oStream...
2
by: bienwell | last post by:
Hi, I have a question about exporting data from datagrid control into Excel file in ASP.NET. On my Web page, I have a linkbutton "Export data". This link will call a Sub Function to perform...
2
by: Snozz | last post by:
The short of it: If you needed to import a CSV file of a certain structure on a regular basis(say 32 csv files, each to one a table in 32 databases), what would be your first instinct on how to...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.