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 8342235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:42:36+00:00 2026-06-09T05:42:36+00:00

i have a student class. class student : DynamicObject { public Dictionary<string, object> dics

  • 0

i have a student class.

class student : DynamicObject
    {
          public Dictionary<string, object> dics = new Dictionary<string, object>();
    }

In am adding properties dynamically to this class.
After i populated a

list<student> lists, 

How i can retrieve the keys and values in the dictionary in the each student class using linq. So that i can bind it to a datagrid. The keys will be same for all the dictionaries in each student object because that will be the column names. The values will different which are the column values. So that i can bind this anonymous type to the datagrid.
I have tried the following way. But the result is not correct.

  var result = lists.SelectMany(x => x.Dictionary.Keys).Select(m => new
                {
                    StudentID = m[1],
                    RegNo = m[2],
                    JoinYear = m[3]
                }).ToList();

finally, i can bind like this,

 grid.DataSource = result;
 grid.DataBind();

So the grid will show the columns from the dictionary keys and all the rows will be populated using the dictionary values. Any help ???

Many thanks.

  • 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-09T05:42:38+00:00Added an answer on June 9, 2026 at 5:42 am

    Your SelectMany is unnecessary – you want to select one row for each student, not one row for each property on each student, so you only need a Select:

    var result = lists.Select(m => new
        {
            StudentID = m.Dict["StudentID"],
            RegNo = m.Dict["RegNo"],
            JoinYear = m.Dict["JoinYear"]
        }); // no need for ToList if you're just binding.
    

    Of coure IMO you’d be far better off using strongly-typed properties on your Student object and populating them properly from your stored procedure; the nyou wouldn’t need anonymous objects here at all.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say i have a object like this public class Student{ public IList<Coursework> Courseworks{get;set;} public
I have created a class student with three properties like this public class Student
I have a class that looks like this class Student { public String str;
I have this schema : public class Student { public String name; public School
Let's have this code : class student :IComparable , IComparable<student> { public string name
Let's say you have a class object: public class Class { IList<Student> students; }
I have a Student object: public class Student { public int Id { get;
I have class student : public class Student { public string Name { get;
I have a document entity Student public class Student { public string Id {
I have a Student class in my application as below: public class Student {

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.