v-alchen
Thu Sep 04 01:05:54 CDT 2008
Hi Mark,
Due to current limitation of Entity Data Model we cannot achieve this by
adding a scaffold property in the partial class.
I have two suggestions for you that can work it around:
1. You can customize the page template. Please refer to this video:
http://www.asp.net/learn/3.5-sp1/video-293.aspx
You can set AutoGenerateColumns to true and add an extra column. Something
like this:
<asp:GridView AutoGenerateColumns="True" ID="GridView1" runat="server"
DataSourceID="GridDataSource"
AllowPaging="True" AllowSorting="True" CssClass="gridview">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
FullName
</HeaderTemplate>
<ItemTemplate>
<%#Eval("FirstName").ToString() + "," +
Eval("LastName").ToString() %>
</ItemTemplate></asp:TemplateField>
<asp:TemplateField>
2. You can hide the LastName field and use a custom field template for the
FirstName field. To do this, Add a FullNameControl in the FieldTemplates
folder:
<%@ Control Language="C#" AutoEventWireup="true"
CodeBehind="FullNameControl.ascx.cs"
Inherits="DynamicAspNetTest.DynamicData.FieldTemplates.FullNameControl" %>
<asp:Literal runat="server" ID="Literal1" Text='<%#
Eval("FirstName").ToString() + "," + Eval("LastName").ToString() %>' />
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace DynamicAspNetTest.DynamicData.FieldTemplates
{
public partial class NameControl :
System.Web.DynamicData.FieldTemplateUserControl
{
public override Control DataControl
{
get
{
return Literal1;
}
}
}
}
Then edit your partial class:
[MetadataType(typeof(PersonMetadata))]
public partial class Person
{
}
public class PersonMetadata
{
//Show FullName in the FirstName column
[UIHint("FullNameControl")]
[DisplayName("FullName")]
public string FirstName { get; set; }
//Hide LastName
[ScaffoldColumn(false)]
public string LastName { get; set; }
}
Please have a try and feel free to ask if you have further questions.
Regards,
Allen Chen
Microsoft Online Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| From: "markla" <markla@noemail.noemail>
| Subject: DynamicData pages and additional fields on an EDM model
| Date: Wed, 3 Sep 2008 02:51:54 -0400
| Lines: 1
| MIME-Version: 1.0
| Content-Type: text/plain;
| format=flowed;
| charset="iso-8859-1";
| reply-type=original
| Content-Transfer-Encoding: 7bit
| X-Priority: 3
| X-MSMail-Priority: Normal
| Importance: Normal
| X-Newsreader: Microsoft Windows Live Mail 12.0.1606
| X-MimeOLE: Produced By Microsoft MimeOLE V12.0.1606
| Message-ID: <ucyeNGZDJHA.4732@TK2MSFTNGP04.phx.gbl>
| Newsgroups:
microsoft.public.dotnet.framework.adonet,microsoft.public.dotnet.framework.a
spnet
| NNTP-Posting-Host: 12-50-98-79.att-inc.com 12.50.98.79
| Path: TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSFTNGP04.phx.gbl
| Xref: TK2MSFTNGHUB02.phx.gbl
microsoft.public.dotnet.framework.aspnet:75165
microsoft.public.dotnet.framework.adonet:11090
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hi,
|
| I have an EDM model, which I'm rendering using DynamicData pages.
|
| I need to add a derived/calculated field.
|
| For example, in a "Person" entity, I have LastName and FirstName. I need
to
| add a derived field FullName (being LastName + ", " + FirstName)
|
| I have tried adding the FullName field to Person's EDM partial class, and
| set the column to be scaffolded, however I can't get FullName to display.
|
| Any tips on how to get derived fields to show in DynamicData pages?
|
| Thanks,
| +Mark
|
|