Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8876153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:08:32+00:00 2026-06-14T19:08:32+00:00

I want to select columns dynamically from List as following. So what could be

  • 0

I want to select columns dynamically from List as following. So what could be the best way?

//a objects list
List<DashBoard> dashboardlist = (List<DashBoard>)objList;  
string strColumns = "RecDate,ModifiedDate";
objList = (from obj in dashboardlist select new { strColumns }).ToList();

/////////////
Ok,Just forget Object List say I have database table which have number of column ID,Name,Age,sex,etc ..Then I have columnList to display and the columnList is change according to condition . SO I have List people; and List columnTemplate; so now I want to select the column based on the template .

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:08:33+00:00Added an answer on June 14, 2026 at 7:08 pm

    Thanks for providing ideas to my question.Spending couple of hours in
    Google I found solution .

    public void Test() {
        var data = new[] {
            new TestData { X = 1, Y = 2, Z = 3 }
        ,   new TestData { X = 2, Y = 4, Z = 6 }
        };
        var strColumns = "X,Z".Split(',');
        foreach (var item in data.Select(a => Projection(a, strColumns))) {
            Console.WriteLine("{0} {1}", item.X, item.Z);
        }
    }
    private static dynamic Projection(object a, IEnumerable<string> props) {
        if (a == null) {
            return null;
        }
        IDictionary<string,object> res = new ExpandoObject();
        var type = a.GetType();
        foreach (var pair in props.Select(n => new {
            Name = n
        ,   Property = type.GetProperty(n)})) {
            res[pair.Name] = pair.Property.GetValue(a, new object[0]);
        }
        return res;
    }
    class TestData {
        public int X { get; set; }
        public int Y { get; set; }
        public int Z { get; set; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Put simply, I want to select all data in two columns from each of
I want to fetch a selected value from a drop down 'select' list of
I want to be able to select the columns that are displayed in my
I m trying to select rows/columns using vba. I want to pass row numbers
I would like my users to select the columns of table they want to
I have table with 3 columns A B C. I want to select *
I have a query with loads of columns. I want to select rows where
Table A, columns OrderId, OrderTimeStamp (datetime). I want to SELECT all records for any
I want to join two tables with several hundred columns, like this: select *
I have table employee I retrieve the columns as select emp_name,emp_add from employee while(iResultSet1.next())

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.