Saturday 6 September 2008

Dynamic Data and Field Templates - An Advanced FieldTemplate with a GridView/DetailsView Project ***UPDATED***

  1. The Anatomy of a FieldTemplate.
  2. Your First FieldTemplate.
  3. An Advanced FieldTemplate.
  4. A Second Advanced FieldTemplate.
  5. An Advanced FieldTemplate with a GridView.
  6. An Advanced FieldTemplate with a DetailsView.
  7. An Advanced FieldTemplate with a GridView/DetailsView Project.

Here is the file based website zipped up no Northwind database you’ll need to provide that yourself as I’m on SQL Server 2008 now :D

UPDATED: I’ve updated the GridView/DetailsView Project it now has ParentDetails and the ChildrenGrid FieldTemplate’s
ParentDetails
no longet support Insert but does support Update as before. Before you try it test it with the Northwind database and this project.

Changes to the project both FieldTemplate now support an attribute that sets which columns to display and now share the IAutoFieldGenerator.

Hope this helps [:D]

13 comments:

Anonymous said...

Hi Steve,

Appreciate your posts / samples...

I am doing a heap of small (non-commercial) web applications for mobile phones. They all share the same SQL Server Database. Just as they do in MySql I prefix the different applications tables with a code (e.g. 001_x_category, 001_d_purchase). I am able to parse the table.name in most pages.

Where there is a foreign key in a DetailView (where showAllRecords = true) there is a link to the lookup table. Is it possible to modify the link text programatically ("View 001_x_category" to "View category").

Thanks again.

Anonymous said...

Just a follow up on my previous comment: found the control that is used for the link (Children.ascx); modified it successfully thanks.

Fathead said...

I'm getting the following error:

System.Web.Query.Dynamic.ParseException: Operator '==' incompatible with operand types 'Guid' and 'String'

My primary keys are Guid's. After googling I found some comments about casting the key to a guid so the comparison can take place, but they all seem to only apply to manually specified where clauses.

I'm not sure how to apply this to a dynamically generated where clause.

Stephen J. Naughton said...

Hi Fathead, you would be better posting this to the DD forum here http://forums.asp.net/1145.aspx I'm not big on GUID's as PK (although they had them in the last project I was on) just join and post someone will certanly have an answer ther if not I'll have a look at that last project.

Steve

James said...

Hi Steve, what would be the level of effort (or any hints you could provide) to implement a combined page-mode Insert command on the child GridView (i.e. Order-Details in your example)? I like how the inline editing works without leaving the page.

Stephen J. Naughton said...

Not much effort at all I have it working from the ChildrenListView_Edit.ascx for one of the article here Which is based on the Later article 3.Custom PageTemplates Part 3 - Dynamic/Templated Grid with Insert (Using ListView)

Hope this helps [:D]

James said...

Thanks for the tip!

Unknown said...

Please forgot previous post, i've found next article: http://csharpbits.notaclue.net/2009/04/cascading-filters-and-fields-dynamic.html

Thank's a lot for your work!!!

Stephen J. Naughton said...

Your welcome ArtCava :)

Let me know if you have any other issues.

Steve :)

John said...

Hi Steve,

Right now the ChildrenGrid only displays when the parent record is in edit mode. How can I have it show both when the parent is in read only mode and edit mode?

I see in article 5 of this series that you say "you will also need to copy the FieldTemplate Children.ascx to GridView.ascx as in the previous post in this series, to have the column show in non edit/insert modes." but neither of those files exist in your source code and I am not sure what it means.

Stephen J. Naughton said...

Hi John, I hounestly can't remember the details of this as it has moved on several generation see http://csharpbits.notaclue.net/2008/09/dynamic-data-custom-pages-with-ajax.html the latest published version.

I imagine that you would just need an _Edit version and one without _Edit to work in both templates.

Steve

Unknown said...

Hi Steve, I am looking for a way to access/change another column's value when using a custom field template. This is so that when type in a name, it can automatically generate a value for another field.
Tried FindOtherFieldTemplate (always returns null) tried to access the control with a hardcoded id (succeeded in finding the control but cannot seem to set the value)... Any suggestions would be most appreciated.

Stephen J. Naughton said...

Hi Tristan, see http://csharpbits.notaclue.net/2009/03/cascading-or-dependant-field-templates.html also send me an e-mail directly (e-mail address is in top right of site)

Steve :)