Discussion:
Gridview, bind column to property of nested type
Ron Young
2008-01-30 16:34:18 UTC
Permalink
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
Ron Young
2008-01-30 16:50:22 UTC
Permalink
Disregard. It was my list<t> initialization code.

-----Original Message-----
From: Discussion of building .NET applications targeted for the Web [mailto:DOTNET-***@DISCUSS.DEVELOP.COM] On Behalf Of Ron Young
Sent: Wednesday, January 30, 2008 10:34 AM
To: DOTNET-***@DISCUSS.DEVELOP.COM
Subject: [DOTNET-WEB] Gridview, bind column to property of nested type

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

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

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