Gridview, bind column to property of nested type

Ron Young <[email protected]> Wed, 30 Jan 2008 10:34:18 -0600
Newsgroups gmane.comp.windows.devel.dotnet.web
Message-ID <[email protected]>
Given the following:

Class UserRole
{
                Public string RoleName { get; set; }
                Public string Description{ get; set; }

                Public override string ToString(){ return RoleName; }
}

Class MyUser
{
                Public  UserRole Role{ get; set; }
                Public string FirstName{ get; set; }
}

I want to bind a list of MyUser to a gridview, and one of the columns in the gridview should display the RoleName of the user.

I thought overriding ToString() in UserRole would do the trick but I get a NullReferenceException.

I know my code to generate a List<MyUser> is correct.

Here's the bound field for that role column in the gridview:


===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com