Copy Code code as follows:
String ccount = "";
The 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 piece of code is the most important
Reportviewer1.reset ();
This. ReportViewer1.LocalReport.LoadReportDefinition (GENERATERDLC ());
ReportViewer1.LocalReport.DataSources.Clear ();
Orders_datatable1 the data source name must be the same as the data source name that this report was originally bound to
This. REPORTVIEWER1.LOCALREPORT.DATASOURCES.ADD (New ReportDataSource ("Orders_datatable1", DS). Tables[0]));
This. ReportViewer1.LocalReport.Refresh ();
}
}
This method is the style of customizing the report
Public MemoryStream GENERATERDLC ()
{
XmlDocument sourcedoc = new XmlDocument ();
String path = AppDomain.CurrentDomain.BaseDirectory + "ORDERS.RDLC";
C_ctime = ds. Tables[0]. rows[0]["C_ctime"]. ToString ();
Sourcedoc.load (path);
Here's the XML operation. I don't have to look at what I need to do.
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);
}
Production period
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 = "Put into production period";
Xmlcellvaluet.innertext = "Put into production period";
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;
}
The technique can be used to design the desired format in the report first.
XmlDocument sourcedoc = new XmlDocument ();
String path = AppDomain.CurrentDomain.BaseDirectory + "ORDERS.RDLC";
Then save the build XML with SourceDoc. Save ()
Can see this XML you need to change the format of which is where