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.