Wednesday, February 24, 2010

Binding foreignkeys and EF's entity by using EntityDataSource to Bindable Controls such as FormView, GridView

Here is a simple case. You have a Client table and a lkpClientType table and they have a referential relationship by lkpClientTypeID. And you want to show the ClientTypeID of the Client table in a data bindable control. How can you do it?

Here is a procedure to follow:
  1. Create a EntityDataSource
  2. Select Client as your source entity. (I assume that you know how to setup a edmx file.)
  3. In VS 2008 designer, select the EDS and hit 'F4' to see a properties window.
  4. Look for an include property field and type "lkpClientType"
  5. Now in your bindable property value do something like <%#Bind("lkpClientType.ClientTypeID")%>

No comments:

Post a Comment