Question

I was wondering if there is some way to name or rename a property on an Anonymous type to include a space in the property name. For example:

var resultSet = from customer in customerList
    select new 
    {
       FirstName = customer.firstName;
    };

In this example I would like FirstName to be "First Name". The reason for this question, is I have a user control that exposes a public DataSource property that I bind to different anonymous type. It is working perfectly right now, except for the one little shortcoming of the column names being a little less than user friendly (FirstName instead of First Name).

Was it helpful?

Solution

What about doing something like this:

var resultSet = from customer in customerList
                select new 
                {
                    Value = customer.firstName,
                    Title = "First Name"
                };

Then in your user control use Value as the contents and Title as the column name.

OTHER TIPS

No, its not possible, spaces are not allowed in the names of members, you can use perhaps underscore or programmatically change the captions of your columns after the data is bound...

I'd add an attribute to the property where you can specify a custom name, and you can provide more user friendly names using the attribute.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top