Link to home
Start Free TrialLog in
Avatar of JMS1965
JMS1965Flag for United States of America

asked on

ASP.NET: Retrieve a lookup value to display in a gridview column

I am building my first web application, using ASP.NET 4 with VB. I'm also using LINQ-to-Entities.

The page I'm working on now will be a listing of Contacts, a gridview based on the "Person" entity, and will display the following columns:

FirstName
LastName
BusName
City
Region

The problem I'm running into is that while FirstName, LastName, and BusName are retrieved directly from the People table (via "Person" entity data source), the City is stored as CityID and Region as RegionID. These ID numbers are linked to an "AttributeName" table, which stores each user's list of cities, regions, phone types, etc. This gridview should not display the CityID and RegionID integers, but should instead display the AttributeName (string) that corresponds to these ID values.

I have set up a template field in the gridview to display the City name, but I can't figure out how to get the name. I have tried both a function and a stored procedure to return the name when provided the ID. I tried calling these from the template field, but it blows up when the CityID is null (which it frequently is).

What would be the best approach to populating a gridview column with the result of a lookup function (or SP), which would also handle nulls? Is there a way to integrate it into the Entity Data Source, and if so, is that a better approach? Or should it be handled in the aspx / vb code, and if so, how can it be configured to work if the CityID is null (in which case it should just display an empty string)?

Thanks very much for any direction you can provide!
ASKER CERTIFIED SOLUTION
Avatar of robasta
robasta
Flag of Zimbabwe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JMS1965

ASKER

Just what I was looking for ... thanks very much!