Click here to Skip to main content
15,904,638 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

HTML
Using SQL server i will fill datatable with values like,

EX:
id	name	tests
1	a	test1
1	a	test2
1	a	test3
1	a	test4
1	a	test5


But i need to show data in the datatable like,

id	name tests
1	a	test1
		test2
		test3
		test4
		test5
Can You please help me for doing this in c#
Posted
Comments
R_Mahesh 29-Nov-12 7:17am    
which back end you are using ?
dimpledevani 29-Nov-12 7:56am    
Use loop and remove the duplicates

1 solution

Hi,

C#
 class SampleData
    {
        public string Id { get; set; }
        public string Name { get; set; }
        public List<string> Tests { get; set; }

    }

private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            DataTable dt = new DataTable();
            //Fill DataTable
            List<sampledata> data = new List<sampledata>();
            foreach (DataRow dr in dt.Rows)
            {
                if (data.Where(sd => sd.Id == dr["Id"].ToString()).ToList().Count == 0)
                {
                    SampleData sampleData = new SampleData();
                    sampleData.Id = dr["Id"].ToString();
                    sampleData.Name = dr["Name"].ToString();
                    sampleData.Tests = new List<string>();
                    sampleData.Tests.Add(dr["Test"].ToString());
                    
                }
                else
                {
                    SampleData s = data.Single(sd => sd.Id == dr["Id"].ToString());
                    s.Tests.Add(dr["Test"].ToString());
                }
            }
        }
</string></sampledata></sampledata></string>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900