Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Controls / March 2008

Tip: Looking for answers? Try searching our database.

Formview and linqdatasource

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
C.R. - 05 Mar 2008 04:26 GMT
I have a formview using a datasource and it works just fine in its basic
format.   However, I have some foreign keys I want to dispay the description
for instead of the key value - just like I do in my gridview.  In the
gridview I use the standard template field as follows:
<asp:TemplateField HeaderText="District" SortExpression="District.Name">
  <ItemTemplate>
     <%#Eval("District.Name")%>
  </ItemTemplate>
</asp:TemplateField>

However when I try something similar in the formview I get no value
displayed for the name:
<asp:Label ID="Label1" runat="server" Text='<%# Eval("District.Name") %>' />
I tried the dropdown list approach using a linqdatasource with Districts to
handle it (I will want the dropdown in the edit and insert templates - but I
don't need it in the itemtemplate).  When I do this I get the error that it
can't use a declaritive datasource.  I am able to get the dropdown approach
shown here http://www.mikepope.com/blog/DisplayBlog.aspx?permalink=1423 by
using a sqldatasource, but I was hoping to use the linq approach and not have
a dropdown on the itemtemplate.
What is the recommended approach for what I am trying to do?  

Thank you in advance.
C.R. Cook
Phil H - 08 Mar 2008 00:24 GMT
> I have a formview using a datasource and it works just fine in its basic
> format.   However, I have some foreign keys I want to dispay the description
[quoted text clipped - 20 lines]
> Thank you in advance.
> C.R. Cook

I am still learning framework v 3 so I don't know much about the
linqdatasource.

However I would like to make one observation for your benefit and
hopefully others about this business of using dropdownlists to select
foreign key values.

It's important to realise that even if the main datasource select
statement includes a descriptive field from a joined table you cannot
use that same datasource to populate the items in a dropdownlist.

You need a unique list (as in select distinct) of all possible values
from the joined table but you wont get that from the main table that
underlies the formview datasource. Hence the datasource that is linked
to the dropdownlist items must be separate with a select statement
involving the joined table on its own (returning the foreign key
values and descriptive text). However the *SelectedValue* of the
dropdownlist *can* and *should* be databound to the main datasource so
that the chosen value is used for updating and inserting the foreign
key value into the main table.

Sorry if I'm telling you what you already know but I'm certain many
people get mixed up over this.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.