HI, i have an datatable like this. i need 开发者_开发知识库to format the data like this.
ID name mailID
12 kumar kumar@gmail.com
14 kumar kumar@gmail.com
17 kumar kumar@gmail.com
20 kiran kiran@gmail.com
21 kiran kiran@gmail.com
26 kiran kiran@gmail.com
100 Ram Ram@gmail.com
101 Ram Ram@gmail.com
102 Ram Ram@gmail.com
now in need to format the data like this in a datatable . can any one help me out how to sort this issue.
ID name mailID
12,14,17 kumar kumar@gmail.com
20,21,26 kiran kiran@gmail.com
100,101,102 Ram Ram@gmail.com
any help would be great
thanks
prince
You shoud store your information about each person in a class, and then call the toString method foreach one you have:
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.
- Use the Linq to dataset group function.
- Create a dictionary with as key your e-mail and as value a list with ints. Iterate your table and add your ids to the right key. Now you can just iterate this dictionary and format it to your output table.
精彩评论