Monday, March 7, 2011

Fetching mutilple columns from Different tables using LinqDataSource and GridView

So after writing about Binding 2 columns of a Table to the DataTextField of Dropdown, I wanted to achieve even further with fetching column values from different tables

So I have a gridview showing Lectures information, which binds the "Title" of the Lecture and "show_id" (foreign key to "shows" table) . What I want to display is the Title of the show rather than just displaying the "show_id".

SharePoint 1015
XCode 1012


SharePoint 101SPTechCon
XCode 101iPhonedevCon

On thing to be kept in mind for this is that you should have a property called "shows" to be able to reference to a foreign table. In short, your DataContext class should have inherited the foreign key reference applied between the shows and the lectures, with shows being the primary table and lectures containing the foreign key.

<%# Eval("Show.show_title") %>

OrderBy="name" TableName="showclasses">

Now when you run the code and there you are. It automatically kind of figures it the mapping between the tables with the "Show.show_title"

No comments:

There was an error in this gadget