Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My datatable is like

----------
BUS
------------------
bus-1,bus-2,bus-3
------------------


I want to display like

-----------
BUS
-----------
bus-1
-----
bus-2
-----
bus-3
-----

How to solve this?
Posted

Hi Manas,
May be below solution give you some idea about your problem .
C#
protected void Page_Load(object sender, EventArgs e)
   {
       DataTable table = new DataTable();
       table = GetTable(table);

       DataTable dtFinal = new DataTable();
       dtFinal.Columns.Add("BUS");

       foreach (var item in table.AsEnumerable())
       {
           if (item[0].ToString().Contains(","))
           {
               string[] arrTemp = item[0].ToString().Split(',');
               foreach (string itemFinal in arrTemp)
               {
                   dtFinal.Rows.Add(itemFinal);
               }
           }
       }
       GridView1.DataSource = dtFinal;
       GridView1.DataBind();
   }

   private DataTable GetTable(DataTable table)
   {
       table.Columns.Add("Header", typeof(string));

       table.Rows.Add("BUS");
       table.Rows.Add("Bus-1,Bus-2,Bus-3");
       return table;
   }


-JMD :-)
 
Share this answer
 
Comments
M.R.A. 24-Aug-13 17:40pm    
thanks a lot....
giri001 24-Aug-13 17:42pm    
your welcome...
giri001 26-Aug-13 1:45am    
Why this answer is downn voted?May i know please :-) thanks.
Design gridview as per your requirement and bind datatable to gridview.
 
Share this answer
 
go for datalist
and add data are table's in it...

repeat columns default it will be zero ...don't change
 
Share this answer
 
v2

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