I would like format the datas of my model thanks to a thousand separator, this datas are in a Datarow and it's not possible to use the toString() with 2 arguments (as shown in my link) on an object.
I think I must parse the Datarow to int then parse this int to a string (using toString("n", nfi)), but my code does not work.
An exception of type 'System.FormatException' occurred in mscorlib.dll but was not processed in the user code Additional information: The format of the input string is incorrect.
Example : listRow.Add(Convert.ToInt64(row["ENTITE"]).ToString("n", nfi));
Datas :
This is the code of my model :
dac = new SqlDataAdapter(sql, cn);
dsc = new DataSet();
dac.Fill(dsc, "histo");
List<List<string>> listHisto = new List<List<string>>();
StringBuilder output = new StringBuilder();
foreach (DataRow row in dsc.Tables["histo"].Rows)
{
CultureInfo.GetCultureInfo("fr-fr");
NumberFormatInfo nfi = (NumberFormatInfo)
CultureInfo.InvariantCulture.NumberFormat.Clone();
nfi.NumberGroupSeparator = " ";
List<string> listRow = new List<string>();
listRow.Add(Convert.ToInt64(row["ENTITE"]).ToString("n", nfi));
listRow.Add(Convert.ToInt64(row["M01"]).ToString("n", nfi));
listRow.Add(Convert.ToInt64(row["M02"]).ToString("n", nfi));
listRow.Add(Convert.ToInt64(row["M03"]).ToString("n", nfi));
listRow.Add(Convert.ToInt64(row["M04"]).ToString("n", nfi));
listRow.Add(Convert.ToInt64(row["M05"]).ToString("n", nfi));
listRow.Add(Convert.ToInt64(row["M06"]).ToString("n", nfi));
listRow.Add(Convert.ToInt64(row["M07"]).ToString("n", nfi));
listRow.Add(Convert.ToInt64(row["M08"]).ToString("n", nfi));
listRow.Add(Convert.ToInt64(row["M09"]).ToString("n", nfi));
listRow.Add(Convert.ToInt64(row["M10"]).ToString("n", nfi));
listRow.Add(Convert.ToInt64(row["M11"]).ToString("n", nfi));
listRow.Add(Convert.ToInt64(row["M12"]).ToString("n", nfi));
listRow.Add(Convert.ToInt64(row["TT"]).ToString("n", nfi));
listHisto.Add(listRow);
}
list.Add("histo", listHisto);
DataTable dtc = dsc.Tables["histo"];
The code of my view :
@{
List<List<string>> listHisto = ViewBag.ListHisto;
bool isClassSuccess = true;
string classLigne;
foreach (List<string> item in listHisto)
{
if (isClassSuccess)
{
classLigne = "class=warning";//jaune clair
isClassSuccess = false;
}
else
{
classLigne = "class=success";//vert clair
isClassSuccess = true;
}
@:<tr @classLigne>
foreach (string row in item)
{
<td>@row</td>
}
@:</tr>
}
Thanks you in advance for your help