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

I want to fetch comma seperated values in gridview.

means i have data like

Name keyskills
aarohi C#,Sql server

I want to fetch this two key skills in different row in gridview.


how can i do this . i use split function but it not works.

help!!!
Posted
Updated 27-Aug-12 21:29pm
v2
Comments
Sandeep Mewara 28-Aug-12 4:59am    
Tried anything?

Hi ,
check this
C#
protected void Page_Load(object sender, EventArgs e)
   {
       string xx = " aarohi C#,Sql server";
      string [] All=  xx.Split(',').ToArray();
      GridView1.DataSource = All;
      GridView1.DataBind();
   }


Best Regards
M.Mitwalli
 
Share this answer
 
Comments
aarohi verma 28-Aug-12 4:13am    
I have to fetch from database.so if i write GridView1.DataSource = All; this it not fetch from database .it only give string result.
Mohamed Mitwalli 28-Aug-12 4:25am    
You mean it's stored in DB like this " aarohi C#,Sql server" and you want apply separated comma on it
aarohi verma 28-Aug-12 4:30am    
ya . aarohi as 'name' and C#,sql server as 'keyskills' is my table and i want to different row in gridview for C# and Sql server.
Mohamed Mitwalli 28-Aug-12 4:39am    
Could you give me your Table Schema Like
Name Keyskills
aarohi sql server , C#

and Final result would be

name Keyskills
aarohi C#
aarohi sql server Am i right

[no name] 28-Aug-12 5:02am    
my 5's....
u r right Mohamed Mitwalli !!!

dear aarohi verma,

ur DataTable contains name column and keyskill column named dTable.
C#
// Create new DataTable.
DataTable myDataTable = new DataTable();
// Declare DataRow variables.
DataRow myRow;
for(int i=0;i<=dTable.rows.count;i++)
{
  myRow = myDataTable.NewRow();
  myRow["name"] = dTable.Row[i][0].ToString();

  //declare string global plz
  string xx = dTable.Row[i][1].ToString();
  string [] All=  xx.Split(',').ToArray();

myRow["keyskill_1"] = All[0].ToString() ;
myRow["keyskill_2"] = All[1].ToString() ;
myDataTable.Rows.Add(myRow);
}
 
Share this answer
 
v2
Comments
Mohamed Mitwalli 28-Aug-12 5:12am    
Karthik this what in my mind but i want to make sure , Hope it help aarohi :)
5+
[no name] 28-Aug-12 5:14am    
Thanks Mohamed!

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