Foreground aspx page
<asp:gridview id= "GridView1" runat= "Server" width= "100%" skinid= "Nviewskintotalstatistics"
>
<Columns>
</Columns>
</asp:GridView>
Back-end. CS Code
1.GV Dynamic Binding
<summary>
Dynamically binding the GridView column
</summary>
void Addgridviewcolumn ()
{
GridView1.Columns.Clear ();
First column
BoundField bfColumn0 = new BoundField ();
Bfcolumn0.datafield = "Month";
Bfcolumn0.headertext = "month";
GRIDVIEW1.COLUMNS.ADD (BfColumn0);
Dynamic acquisition of nuclear medicine reagent name
DataTable nuclearmedicinename = new DataTable ();
Nuclearmedicinename = new Ristotalmanage (). Getnuclearmedicinename ();
ienumerable<string> l_nuclearmedicinename = new list<string> ();
L_nuclearmedicinename = Nuclearmedicinename.asenumerable (). Select (t = t.field<string> (pub_dictionary. F_dicvalue));
foreach (var it in L_nuclearmedicinename)
{
BoundField bf = new BoundField ();
The name of the field that represents the table bound to the column
Bf. DataField = it;
Represents the name of the column
Bf. HeaderText = it;
GRIDVIEW1.COLUMNS.ADD (BF);
}
Radionuclide Treatment Volume column
BoundField bfcolumnend = new BoundField ();
Bfcolumnend.datafield = "Counts";
Bfcolumnend.headertext = "radionuclide Treatment volume";
GRIDVIEW1.COLUMNS.ADD (Bfcolumnend);
Gridview1.width = 12 * 60;
GridView1.RowStyle.HorizontalAlign = Horizontalalign.center;
}
Dynamic generation of a DataTable in the same format as GV after 2.GV dynamic binding
void Addstatisticscolumn (ref DataTable Dtstatistics)
{
DataColumn Dcclientdepart = new DataColumn ("Month", typeof (String));
Dcclientdepart.caption = "month";
DTSTATISTICS.COLUMNS.ADD (Dcclientdepart);
Dynamic acquisition of nuclear medicine reagent name
DataTable nuclearmedicinename = new DataTable ();
Nuclearmedicinename = new Ristotalmanage (). Getnuclearmedicinename ();
ienumerable<string> l_nuclearmedicinename = new list<string> ();
L_nuclearmedicinename = Nuclearmedicinename.asenumerable (). Select (t = t.field<string> (pub_dictionary. F_dicvalue));
foreach (var it in L_nuclearmedicinename)
{
DataColumn dcname = new DataColumn (it, typeof (String));
Dcname.caption = it;
DTSTATISTICS.COLUMNS.ADD (dcname);
}
DataColumn dccounts = new DataColumn ("Counts", typeof (String));
dccounts.caption = "radionuclide Treatment volume";
DTSTATISTICS.COLUMNS.ADD (dccounts);
}
3. Fill DataTable data and assign to GV to complete the operation
DataTable dtstatistics = new DataTable ();
Construct a DataTable in the same format as GV
Addstatisticscolumn (ref dtstatistics); Step Two
if (Dtmaskulin = = null) return null;
if (DtMaskulin.Rows.Count = = 0) return dtmaskulin;
All reagent names
DataTable nuclearmedicinename = new DataTable ();
Nuclearmedicinename = new Ristotalmanage (). Getnuclearmedicinename ();
ienumerable<string> l_nuclearmedicinename = new list<string> ();
L_nuclearmedicinename = Nuclearmedicinename.asenumerable (). Select (t = t.field<string> (pub_dictionary. F_dicvalue));
Start populating data
for (int i = 1; i <=; i++)
{
DataRow drNew1 = Dtstatistics.newrow ();
if (i = =)
{
drnew1["Month"] = "total";
for (int j = 0; J < DtMaskulin.Rows.Count; J + +)
{
DrNew1 [dtmaskulin.rows[j]["Contrastagentname"]. ToString ()] = drnew1[dtmaskulin.rows[j]["Contrastagentname"]. ToString ()] = Dtmaskulin.compute ("sum (dosages)", String. Format ("Contrastagentname= ' {0} '", dtmaskulin.rows[j]["Contrastagentname"]));
}
drnew1["Counts"] = Dtmaskulin.compute ("sum (dosages)", "");
}
Else
{
drnew1["month"] = i + "months";
drnew1["Counts"] = Dtmaskulin.compute ("sum (dosages)", String. Format ("DateTimes = ' {0} '", Syear + "-" + i.tostring (). GETSTR (2)));
for (int j = 0; J < DtMaskulin.Rows.Count; J + +)
{
drnew1[dtmaskulin.rows[j]["Contrastagentname"]. ToString ()] = Dtmaskulin.compute ("sum (dosages)", String. Format ("Contrastagentname= ' {0} ' and DateTimes = ' {1} '", dtmaskulin.rows[j]["contrastagentname"],syear + "-" + I. ToString (). GETSTR (2));
}
}
DtStatistics.Rows.Add (drNew1);
}
return dtstatistics;
About GV and DataTable dynamic binding