Click here to Skip to main content
15,886,864 members
Please Sign up or sign in to vote.
1.20/5 (2 votes)
See more:
Hi everyone, how to get columns name from list.
HTML
Col1    Col2
1        10
2        12
3        13


</pre>


I want to get list columns name like below
Col1
Col2
Posted
Updated 2-Jul-18 2:39am
Comments
[no name] 14-Oct-14 8:10am    
You want to get from what?
If these are inthe view then the column names must be the Property Name of the Model.
Please brief what exactly you want and from what?
[no name] 14-Oct-14 11:08am    
Can you explain your problem with code
[no name] 15-Oct-14 0:13am    
can u explain your problem in detail
SRS(The Coder) 15-Oct-14 1:36am    
What kind of list is this ?
Can you please add some code here ?
Gopal Rakhal 16-Oct-14 7:25am    
Not in View rather in controller
List<PovertyModel> tempPovertyList = new List<PovertyModel>();
tempPovertyList = ent.Database.SqlQuery<PovertyModel>("PopulatePovertyRecords").ToList();

Now I want to get the list of fieldname/columns name in tempPovertyList.....

1 solution

am proving sample code please try this

List<object> g = new List<object>() { new  { a = 1, s = 2, d = 3 }, new  { a = 1, s = 2, d = 3 } };
       
            foreach (object item in g)
            {
                object n = item.GetType().GetProperties().Select(k => k.Name).ToList();
            }
 
Share this answer
 
Comments
Gopal Rakhal 16-Oct-14 7:39am    
Its works fine, m getting all columns name but it is necessary to loop through all rows, Is there any way to not loop all rows.
Thanks a lot

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