Add a horizontal longitudinal total in DataGrid (realized in DataTable, DataBLE downside data)

zhaozj2021-02-16  51

9CBS - Document Center - .NET title to DataGrid plus horizontal longitudinal total (realization in DataTable, DataAding) Dragonsuc (original) keyword DataTable

Is there a final result if implemented? ?

Protected system.web.ui.webcontrols.dataGrid DataGrid1;

///

/// Data Sources

///

DataSet CreateDataSource ()

{

DataTable DT = New DataTable ();

DataRow DR;

Dt.columns.Add (New Datacolumn ("Name", TypeOf (String));

Dt.columns.add (New Datacolumn ("Value1", TypeOf (INT32));

Dt.columns.add (New Datacolumn ("Value2", TypeOf (INT32)));

Dt.columns.add (New Datacolumn ("Value3", TypeOf (INT32));

Dt.columns.add (New Datacolumn ("Value4", TypeOf (INT32));

For (int i = 0; i <10; i )

{

DR = DT.NEWROW ();

DR [0] = I.toTOString () "Name";

DR [1] = i;

DR [2] = i 1;

DR [3] = i 2;

DR [4] = i 3;

DT.ROWS.ADD (DR);

}

Dataset mydata = new dataset ();

MyData.tables.Add (DT);

Return mydata;

}

Private Void Page_Load (Object Sender, System.EventArgs E)

{

/ / Place the user code here to initialize the page

Dataset mydata = createDataSource ();

// DataGrid1.datasource = mydata;

// DataGrid1.databind ();

DataTable myTable = new dataable ();

Datacolumn mycolum;

Foreach (datacolumn nowdatacolumn in mydata.tables [0] .columns)

{

Mycolum = new datacolumn ();

mycolum.datatype = nowDatacolumn.DataType;

Mycolum.columnname = nowDatacolumn.columnname;

MyTable.Columns.Add (MyColum);

}

Mycolum = new datacolumn ();

MyColum.DataType = system.type.gettype ("System.Int32");

Mycolum.columnname = "Total per line";

MyTable.Columns.Add (MyColum);

DataRow acountrow;

INT Datacolumns = mydata.tables [0] .columns.count;

Foreach (DataRow Nowrow In MyData.tables [0] .ROWS) {

Acountrow = mytable.newrow ();

Acountrow.itemarray = NOWROW.ITEMARRAY;

// Total per line

GetrowAccount (AcountRow, 1, 5, Datacolumns);

MyTable.Rows.Add (ACOUNTROW);

}

// Generate the total

Acountrow = mytable.newrow ();

ACOUNTROW [0] = "Agreement";

For (int count = 1; count

Foreach (DataRow Nowrow In MyTable.Rows)

{

IF (! acountrow.isnull (count))

{

IF (! acountrow.isnull (count))

ACOUNTROW [count] = convert.Toint32 (ACOUNTROW [count]) Convert.Toint32 (nowrow [count]);

}

Else acountrow [count] = norow [count] ;;

}

MyTable.Rows.Add (ACOUNTROW);

DataGrid1.datasource = MyTable;

DataGrid1.databind ();

}

///

/// Total per line

///

Private Void Gtrowaccount (DataRow AcountRow, Int Begincol, Int Endcol, Int Acountcol)

{

For (int I = begincol; i

{

if (! ACOUNTROW.INULL (Accountcol)

{

IF (! acountrow.isnull (i))

ACOUNTROW [Accountcol] = Convert.Toint32 (ACOUNTROW [Accountcol]) Convert.Toint32 (ACOUNTROW [I]);

}

Else AcountRow [Accountcol] = ACOUNTROW [i];

}

}

Disadvantages: Accessing all the data is not very good

There are other ways if there is a better way, please tell me.

转载请注明原文地址:https://www.9cbs.com/read-18539.html

New Post(0)