2010-08-16 3 views
0

HI, J'ai un datatable comme ceci. J'ai besoin de formater les données comme ça.Données de formatage à l'intérieur d'une datable

ID name  mailID 
12 kumar  [email protected] 
14 kumar  [email protected] 
17 kumar  [email protected] 
20 kiran  [email protected] 
21 kiran  [email protected] 
26 kiran  [email protected] 
100 Ram   [email protected] 
101 Ram   [email protected] 
102 Ram   [email protected] 

maintenant besoin de formater les données comme ceci dans un datatable. quelqu'un peut-il m'aider à régler ce problème?

ID   name  mailID 
12,14,17  kumar  [email protected] 
20,21,26  kiran  [email protected] 
100,101,102 Ram  [email protected] 

toute aide serait grande

grâce

prince

Répondre

2

vous shoud stocker vos informations sur chaque personne dans une classe, puis appelez une méthode toString foreach vous:

public class Struct 

     { 

      private int[] numbers; 

      private string email; 

      private string name; 



      public string Name { 

       get { return name; } 

      } 



      public string Email { 

       get { return email; } 

      } 



      public int[] Numbers { 

       get { return numbers; } 

      } 



      private void init(string name, string email, int[] numbers) 

      { 

       this.name = name; 

       this.email = email; 

       this.name = numbers; 

      } 



      public Struct(string name, string email, int number) 

      { 

       init(name, email, new int[]{ number }); 

      } 



      public Struct(string name, string email, int[] numbers) 

      { 

       init(name, email, numbers); 

      } 



      public override string toString() 

      { 

       string toret = ""; 



       foreach(var num in this.numbers) { 

        toret += Convert.ToString(num); 

        toret += '\t'; 

        toret += Name; 

        toret += '\t'; 

        toret += Email; 

        toret += '\n'; 

       } 


          return toret; 
      } 

     } 

Hope this helps.

0
  1. Utilisez la fonction de groupe Linq to dataset .
  2. Créez un dictionnaire avec comme clé votre e-mail et comme valeur une liste avec ints. Itérez votre table et ajoutez vos identifiants à la touche droite. Maintenant vous pouvez juste parcourir ce dictionnaire et le formater à votre table de sortie.