Vinicius Cano
Vinicius Cano

Reputation: 319

DataValue field value C#

I am doing a project and can't make a Seletect Value from a list get the right value.A list is generated from a class UserDepartment,in this class I have this basically:

public class UserDepartment
{
    public long ID { get; set; }
    public string Description { get; set; }
    public User UserResponsible { get; set; }
}

The Problem is that I need a value from the class userResponsible,inside there is a value called EDV, I need this value but I don't know how to get.See this image below:

List Generated

If I use " ListBeneficiaryArea.DataValueField = "ID"; ",I get the ID value normally,but i cant get the EDV value, I already tried "EDV","UserResponsible.EDV" and "UserResponsible"but it didn't work.

There is other way for me to get the UserResponsible.EDV in the DataValueField?

After the change in DataSource i received this error:

enter image description here

Upvotes: 1

Views: 538

Answers (1)

Curtis
Curtis

Reputation: 103388

You can change your DataSource to the following:

ListBeneficiaryArea.DataSource = from a in lstBUAreas
                                 select new { ID, EDV = a.UserResponsible.EDV };

Then you can do:

ListBeneficiaryArea.DataTextField = "ID";
ListBeneficiaryArea.DataValueField = "EDV";

Upvotes: 3

Related Questions