473,612 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Exporting the contebts of repeater to excel.

2 New Member
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_ItemCre ated(object sender, RepeaterItemEve ntArgs e)
{
string vehicleNo = Convert.ToStrin g(DataBinder.Ev al(e.Item.DataI tem, "Vehicle No"));



if (e.Item.ItemInd ex > 0 && DataVehicleNumb er != vehicleNo && (e.Item.ItemTyp e == ListItemType.It em || e.Item.ItemType == ListItemType.Al ternatingItem))
{
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&n bsp; : &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(tc 1);
tr.Cells[0].CssClass = "datavalue" ;
tr.Cells.Add(tc 2);
tr.Cells[1].CssClass = "datavalue" ;
tr.Cells.Add(tc 3);
tr.Cells[2].CssClass = "datavalue" ;
tr.Cells.Add(tc 4);
tr.Cells[3].CssClass = "datavalue" ;
tr.Cells.Add(tc 5);
tr.Cells[4].CssClass = "datavalue" ;
tr.Cells.Add(tc 6);
tr.Cells[5].CssClass = "datavalue" ;

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

tr.Cells.Add(tc 7);
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.A dd(lblSlno);
Otc0.CssClass = "datavalue" ;
Otr.Cells.Add(O tc0);

Otc1.Text = Convert.ToStrin g(DataBinder.Ev al(e.Item.DataI tem, "Vehicle No"));
Otc1.CssClass = "datavalue" ;
Otr.Cells.Add(O tc1);
Otc2.Text = Convert.ToStrin g(DataBinder.Ev al(e.Item.DataI tem, "Service Type"));
Otc2.CssClass = "datavalue" ;
Otr.Cells.Add(O tc2);
Otc3.Text = Convert.ToStrin g(DataBinder.Ev al(e.Item.DataI tem, "Odometer") );
Otc3.CssClass = "datavalue" ;
Otr.Cells.Add(O tc3);
Otc4.Text = Convert.ToStrin g(DataBinder.Ev al(e.Item.DataI tem, "Bill No"));
Otc4.CssClass = "datavalue" ;
Otr.Cells.Add(O tc4);
Otc5.Text = Convert.ToDateT ime(DataBinder. Eval(e.Item.Dat aItem, "Bill Date")).ToStrin g("dd/MM/yyyy");
Otc5.CssClass = "datavalue" ;
Otr.Cells.Add(O tc5);
Otc6.Text = String.Format(" {0:N}",DataBind er.Eval(e.Item. DataItem, "Amount"));
Otc6.CssClass = "datavalue" ;
Otc6.Attributes .Add("align", "right");
Otr.Cells.Add(O tc6);

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

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

if (e.Item.ItemTyp e == ListItemType.Fo oter)
{
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&n bsp; : &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(tc 1);
tr.Cells[0].CssClass = "datavalue" ;
tr.Cells.Add(tc 2);
tr.Cells[1].CssClass = "datavalue" ;
tr.Cells.Add(tc 3);
tr.Cells[2].CssClass = "datavalue" ;
tr.Cells.Add(tc 4);
tr.Cells[3].CssClass = "datavalue" ;
tr.Cells.Add(tc 5);
tr.Cells[4].CssClass = "datavalue" ;
tr.Cells.Add(tc 6);
tr.Cells[5].CssClass = "datavalue" ;

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

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

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



protected void Content_OnItemD ataBound(object sender, RepeaterItemEve ntArgs e)
{
//double totamount;
if (e.Item.ItemTyp e == ListItemType.It em || e.Item.ItemType == ListItemType.Al ternatingItem)
{
if ((Label)e.Item. FindControl("lb lid") != null)
((Label)e.Item. FindControl("lb lid")).Text = (e.Item.ItemInd ex + 1).ToString();


if (DataVehicleNum ber == DataBinder.Eval (e.Item.DataIte m, "Vehicle No").ToString() )
{
if (((Label)e.Item .FindControl("l blVehicleNumber ")) != null)
((Label)e.Item. FindControl("lb lVehicleNumber" )).Text = "&nbsp;";

Total += Convert.ToDoubl e(DataBinder.Ev al(e.Item.DataI tem, "Amount"));
//((Label)e.Item. FindControl("lb lTotal")).Text = "Total :" + Total.ToString( );


//((Label)e.Item. FindControl("lb lVehicleNumber" )).Text = "&nbsp;";
//Total += Convert.ToInt64 (DataBinder.Eva l(e.Item.DataIt em, "Amount"));
//((Label)e.Item. FindControl("lb lTotal")).Text = "Total :" + Total.ToString( );
}

else
{
Total = 0;
DataVehicleNumb er = DataBinder.Eval (e.Item.DataIte m, "Vehicle No").ToString() ;
Total += Convert.ToDoubl e(DataBinder.Ev al(e.Item.DataI tem, "Amount"));
// //((Label)e.Item. FindControl("lb lTotal")).Text = "Total :" + Total.ToString( );

}
}
}
protected void btn_Export_Clic k(object sender, EventArgs e)
{

Response.Buffer = true;
Response.Conten tType = "applicatio n/vnd.ms-excel";
Response.AddHea der("Content-Disposition", "attachment;fil ename=VehicleWi seExpenses.xls" );
Response.Charse t = "";
this.EnableView State = true;
System.IO.Strin gWriter oStringWriter = new System.IO.Strin gWriter();
System.Web.UI.H tmlTextWriter oHtmlTextWriter = new System.Web.UI.H tmlTextWriter(o StringWriter);
Content.RenderC ontrol(oHtmlTex tWriter);
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.T oString());

Response.End();

}


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

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

Similar topics

3
9237
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 only exporting to single worksheet. but i need to export data to multiple worksheets. it is very urgent to us. so please help me in code.
4
3941
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" TEXT field that contains data such as 2000/01, 2001/02, etc. If I export a Query with this kind of data to Excel, it gives me the text value of this field; however, when I export a Report bound to this TEXT field, Excel gives me the values 36526,...
2
7700
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
7993
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
1092
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 with a Repeater (the HTML code goes to the spreadsheet). Does anyone here knows how to do that?
2
6919
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 want to see it in PDF or EXCEL etc etc..... What I am trying to acheive is depending on their choice of format, I want to send the stream of that particulae selected format to the browser. I have tried couple od solutions but I couldn't able to get...
1
3155
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 As System.IO.MemoryStream = 3 myReport.ExportToStream( ExportFormatType.PortableDocFormat) 4 Response.Clear() 5 Response.Buffer() = True
2
2400
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 exporting ALL data from the datagrid control. Exporting data works fine when I show all data on the datagrid control. I'd like to shows only 30 records on the datagrid control instead of ALL data using page navigation, and perform exporting...
2
3168
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 set this up so as to do it reliably and minimize overhead? There are currently no constraints on the destination table. Assume the user or some configuration specifies the database name, server name, and filename+fullpath. The server is SQL...
0
8162
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8605
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8246
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8415
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7039
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5532
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4045
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4109
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1413
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.