I. arraylist stores two-dimensional arrays.
Why is arraylist used?
Arraylist is a dynamic array. It can declare and strengthen without knowing the length, and can be modified as needed.
State to increase the length, size, and delete any index content. These are not available in common arrays.
String [] get_num = new string [3]; // creates a cute array for your examples
Get_num [0] = "8, 5, 12, 12 ";
Get_num [1] = "82,52, 52,42 ";
Get_num [2] = "112,132 ";
Arraylist Al = new arraylist (); // declare and strengthen a silly arraylist
Arraylist Al = new arraylist (); // declare and strengthen a silly arraylist
For (INT I = 0; I <get_num.length; I ++)
{
String [] get_numarray = get_num [I]. Split (','); // cut the ordinary array according to ","
For (Int J = 0; j <get_numarray.length; j ++)
{
Al2.add (double) (double. parse (get_numarray [J]); // The default value of this example is the double class.
Type to add the second-dimensional content to Al 2.
}
Al. Add (double []) al2.toarray (typeof (double); // Add the content of the first dimension to Al
Al2.clear (); // clear the content to avoid the second-dimensional Accumulation
}
Double [] [] get_countnum = (double [] []) Al. toarray (typeof (double []); // OK! He's full, Al is transferred
Convert to a 2-dimensional array
Ii. Percentage "Rounding Problem"
String AAA = "48"
String BBB = "976"
God wants to divide 48 by 976 and then the result is rounded to two decimal places.
OK! I will tell you how to solve the problem of God.
Note the following:
You must convert the value involved in the operation to a double or float type. If you convert the value to an integer, the decimal point cannot be obtained.
.(
(Double) (Int. parse (AAA) * 100)/double. parse (BBB). tostring ("F2 ");
OK! Finished! In tostring brackets after the result is converted to double-precision percentage, F indicates converting "precision percentage data ".
"The two digits after the decimal point are retained. You can replace them with 3, 4 or other digits as needed.
3. Merge cells in the gridview footer.
For example, if the "Ipsos test project" is centered in the footer of the gridview, it has been merged by cells,
The Code is as follows:
Protected void gridview1_rowdatabound (Object sender, gridviewroweventargs e) // triggered when you define a row
{
If (E. Row. rowtype = datacontrolrowtype. footer) // if the current row is a footer
{
E. Row. cells [0]. columnspan = E. Row. cells. Count; // length of all cells in the cell site
E. Row. cells [0]. horizontalalign = horizontalalign. Center; // center
E. Row. cells [0]. Text = request. querystring ["projectname"]; // The request. querystring ["projectname"] Here is the "Ipsos test project"
For (INT I = 1; I <E. Row. cells. Count; I ++)
{
E. Row. cells [I]. attributes ["style"] = "display: none;"; // remove other footer cells.
}
}
}
4. cyclically retrieve the data results of datareader
Sqldatareader DR = sqlcommand. excutereader ();
Do
{
While (dr. Read ())
{
Panel_id + = Dr ["Name of a column"]. tostring () + ","; // use commas (,) to separate multiple columns
}
}
While (dr. nextresult (); // obtain the next