Bonjour,
Voici le contexte de mon problème, je remplis un GridView à partir d'une procédure stockée que j'ai en base, tout se passe bien jusque là, après pour traiter et modifier plus aisément ces données j'ai besoin de les stocker dans une DataTable, mais seulement il y a un problème lors de ce transfert. Toutes les Strings comportant des accents ou des apostrophes ne sont pas diffèrent de celles du GridView. Par exemple pour "Maman j'ai raté l'avion" j'obtiens :dans ma DataTable (les espaces sont volontaires) ! Avez-vous une idée pour que la DataTable prenne en compte des accents ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part "Maman j & # 3 9;ai rat & # 2 3 3; l& # 3 9;avion"
Voici mon code qui réalise la Datatable :
Merci d'avance pour vos réponses
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83 DataTable GetTable() { DataTable dt = new DataTable(); dt.Columns.Add("Label"); dt.Columns.Add("CategoryId"); dt.Columns.Add("ProgramId"); dt.Columns.Add("Title"); dt.Columns.Add("ShopName"); dt.PrimaryKey = null; #region Conversion dt.Columns[0].DataType = Type.GetType("System.String"); foreach (DataRow dr in dt.Rows) { dt.ImportRow(dr); } dt.AcceptChanges(); dt.Columns[1].DataType = Type.GetType("System.Int32"); foreach (DataRow dr in dt.Rows) { dt.ImportRow(dr); } dt.AcceptChanges(); dt.Columns[2].DataType = Type.GetType("System.String"); foreach (DataRow dr in dt.Rows) { dt.ImportRow(dr); } dt.AcceptChanges(); dt.Columns[3].DataType = Type.GetType("System.String"); foreach (DataRow dr in dt.Rows) { dt.ImportRow(dr); } dt.AcceptChanges(); dt.Columns[4].DataType = Type.GetType("System.String"); foreach (DataRow dr in dt.Rows) { dt.ImportRow(dr); } dt.AcceptChanges(); #endregion foreach (GridViewRow ligne in GridViewShops2.Rows) { DataRow dr = dt.NewRow(); if (ligne.Cells[4].Text != null) { HtmlString hs = new HtmlString(ligne.Cells[4].Text); dr["ShopName"] = hs; } if (ligne.Cells[3].Text != null) { HtmlString hs = new HtmlString(ligne.Cells[3].Text); dr["Title"] = hs; } if (ligne.Cells[2].Text != null) { HtmlString hs = new HtmlString(ligne.Cells[2].Text); dr["ProgramId"] = hs; } //if (ligne.Cells[1].Text != null) //{ // HtmlString hs = new HtmlString(ligne.Cells[1].Text); dr["CategoryId"] = ligne.Cells[1].Text; //} if (ligne.Cells[0].Text != null) { HtmlString hs = new HtmlString(ligne.Cells[0].Text); dr["Label"] = hs; } //dr["Label"] = ligne.Cells[0].Text; //dr["CategoryId"] = ligne.Cells[1].Text; //dr["ProgramId"] = ligne.Cells[2].Text; //dr["Title"] = ligne.Cells[3].Text; //dr["ShopName"] = ligne.Cells[4].Text; dt.PrimaryKey = null; dt.Rows.Add(dr); } return dt; }
Partager