Due to the company's demand, Microsoft's reportviewer has many special requirements, so dynamic calling is flexible.
My requirement is to merge headers based on different data(Thanks again for reading any blog document you want)
Code
String Ccount = "" ;
String Dcount = "" ;
String Jcount = "" ;
Protected Void Page_load ( Object Sender, eventargs E)
{
If ( ! Ispostback)
{
String ID = Request. querystring [ " Orderid " ] = Null ? " 1 " : Request. querystring [ " Orderid " ]. Tostring ();
Sqlconnection con = New Sqlconnection ( " Server = chenzq; uid = sa; Pwd = luca623; database = Luca " );
Sqldataadapter SDA = New Sqldataadapter ( " Select * From view_order where c_orderid =' " + ID + " ' " , Con );
Dataset DS = New Dataset ();
SDA. Fill (DS );
Ccount = DS. Tables [ 0 ]. Rows [ 0 ] [ " C_ctime " ]. Tostring ();
Dcount = DS. Tables [ 0 ]. Rows [ 0 ] [ " C_ttime " ]. Tostring ();
Jcount = DS. Tables [ 0 ]. Rows [ 0 ] [ " C_dtime " ]. Tostring ();
// This sectionCodeIs the most important
Reportviewer1.reset ();
This . Reportviewer1.localreport. loadreportdefinition (generaterdlc ());
Reportviewer1.localreport. CES. Clear (); // orders_datatable1 the data source name must be the same as the data source name originally bound to this Report
This . reportviewer1.localreport. datasources. add ( New reportdatasource ( " orders_datatable1 " , DS. tables [ 0 ]);
This . reportviewer1.localreport. refresh ();
}< br> // you can customize the report style.
Public memorystream generaterdlc ()
{< br> xmldocument sourcedoc = New xmldocument ();
StringPath=Appdomain. currentdomain. basedirectory+ "Orders. rdlc";
//C_ctime = Ds. Tables [0]. Rows [0] ["c_ctime"]. tostring ();
Sourcedoc. Load (PATH );
// The following is the XML operation. You do not need to view what I do as needed.
Xmlnode xheader = Sourcedoc. childnodes. Item ( 1 ). Childnodes. Item ( 13 ). Childnodes. Item ( 1 ). Childnodes. Item ( 0 ). Childnodes. Item ( 4 );
Xmlnode xcells = Xheader. childnodes. Item ( 0 ). Childnodes. Item ( 0 ). Childnodes. Item ( 0 );
// Construction Period
Xmlnode xmlcell = Xcells. childnodes. Item ( 1 );
Xmlelement xecol = Sourcedoc. createelement ( " Colspan " );
Xecol. innertext = Ccount;
Xecol. innerxml = Ccount;
Xmlcell. innerxml + = Xecol. outerxml;
Xmlnode xmlcellvalue = Xmlcell. childnodes. Item ( 0 ). Childnodes. Item ( 0 ). Childnodes. Item ( 4 );
Xmlcellvalue. innerxml = " Construction Period " ;
Xmlcellvalue. innertext = " Construction Period " ;
Xmlnode xnremove;
For ( Int I = 0 ; I < Int . Parse (ccount) - 1 ; I ++ )
{
Xnremove= Xcells. childnodes. Item ( 2 );
Xcells. removechild (xnremove );
}
// Delivery Date
Xmlnode xmlcellt = Xcells. childnodes. Item ( 2 );
Xmlelement xecolt = Sourcedoc. createelement ( " Colspan " );
Xecolt. innertext = Dcount;
Xecolt. innerxml = Dcount;
Xmlcellt. innerxml + = Xecolt. outerxml;
Xmlnode xmlcellvaluet = Xmlcellt. childnodes. Item ( 0 ). Childnodes. Item ( 0 ). Childnodes. Item ( 4 );
Xmlcellvaluet. innerxml = " Delivery Date " ;
Xmlcellvaluet. innertext = " Delivery Date " ;
For ( Int J = 0 ; J < Int . Parse (dcount) - 1 ; J ++ )
{
Xnremove=Xcells. childnodes. Item (3);
Xcells. removechild (xnremove );
}
// Production Period
Xmlnode xmlcellc = Xcells. childnodes. Item ( 3 );
Xmlelement xecolc = Sourcedoc. createelement ( " Colspan " );
Xecolc. innertext = Jcount. tostring ();
Xecolc. innerxml = Jcount. tostring ();
Xmlcellc. innerxml + = Xecolc. outerxml;
Xmlnode xmlcellvaluec = Xmlcellc. childnodes. Item ( 0 ). Childnodes. Item ( 0 ). Childnodes. Item ( 4 );
Xmlcellvaluec. innerxml = " Production Period " ;
Xmlcellvaluec. innertext = " Production Period " ;
For ( Int J = 0 ; J < Int . Parse (jcount) - 1 ; J ++ )
{
Xnremove = Xcells. childnodes. Item ( 4 );
Xcells. removechild (xnremove );
}
Memorystream MS = New Memorystream ();
Xmlserializer serializer = New Xmlserializer ( Typeof (Xmldocument ));
Serializer. serialize (MS, sourcedoc );
Ms. Position = 0 ;
Return MS;
}
Xmldocument sourcedoc = new xmldocument ();
String Path = appdomain. currentdomain. basedirectory + "orders. rdlc ";
Then use sourcedoc. Save () to save and generate xml
You can see where the XML format you need to change is.
TIPS: first, design the required format in the report.