Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Formview and linqdatasource

Reply
Thread Tools

Formview and linqdatasource

 
 
C.R.
Guest
Posts: n/a
 
      03-05-2008
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/Display...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
 
Reply With Quote
 
 
 
 
Phil H
Guest
Posts: n/a
 
      03-08-2008
On 5 Mar, 04:26, C.R. <(E-Mail Removed)> wrote:
> 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 - butI
> don't need it in the itemtemplate). *When I do this I get the error thatit
> can't use a declaritive datasource. *I am able to get the dropdown approach
> shown herehttp://www.mikepope.com/blog/DisplayBlog.aspx?permalink=1423by
> 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


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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LinqDataSource and GridView.RowDataBound david ASP .Net 3 07-26-2008 10:15 PM
ListView ItemUpdating OldValues and NewValues collections Empty (linqDataSource) Marius Manolea ASP .Net 0 06-04-2008 04:40 PM
LINQDataSource / FormView - automatically updating child records Jay Pondy ASP .Net 0 04-04-2008 11:27 AM
Concurrency / LINQDataSource / FormView / Stored Procedures Jay Pondy ASP .Net 9 03-28-2008 05:04 PM
ListView and LinqDataSource. Delete item shapper ASP .Net 1 02-19-2008 05:27 PM



Advertisments