Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
hello,

i need to show a gird view in a page having data with comma in between them.

example of data in the table..
emp id.........emp Language
1.................English
2.................Russian
1.................Spanish
1.................American
2.................Chinise


i need to show the grid view like:

emp id........emp language
1................English,Spanish,American
2.................Russian,Chinise


please help ...

thanx in advance.
Posted

1 solution

Hi Ishan,

Write your query with the COALESCE option. This will resolve your problem.

SQL
SELECT empid ,REPLACE(RTRIM((SELECT empLanguage + ' ' FROM TableName WHERE ( empid  = Results.empid  ) FOR XML PATH (''))),' ',', ') AS NameValues
FROM TableName Results
GROUP BY empid 


Apply below code to bind checkbox

C#
for(int i=0;i<lstCheckBox.Items.Count;i++)
{ 
   for(int j=0;j<ds.Table[0].Rows.Count;j++)
   {
      if(lstCheckBox.Items[i].Value == ds.Table[0].Rows[j]["LanguageId"].ToString())
           lstCheckBox.Items[i].Selected = true;
   }
}
 
Share this answer
 
v4
Comments
[no name] 28-Nov-12 0:44am    
hello Mukhtar,
can u give me an example please..
Mohd. Mukhtar 28-Nov-12 0:57am    
Yeah sure please have a look above query and try to run.
[no name] 28-Nov-12 1:41am    
can u help me out once more...
how to repopulate this languages names to checkbox list...
Mohd. Mukhtar 28-Nov-12 1:45am    
If you want to repopulate then you need to split the language with "," separator and after that you can bind checkbox.
[no name] 28-Nov-12 1:54am    
but i need to bind the checkbox with both the value and text.
language names are only the text but the values are the language id.
can u give me an example please.

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