I am using Dynamic Data 4 and in order to create data model i use ADO.NET Entity Framework.
I have table Organization and table Firms. Table Organization has a references to the Firms table.
First of all, when i am in the Organization List.aspx page i am setting the filter by Firms then i press on DynamicHyperLink and i go on Insert.aspx page, but the DropDownList in the Insert page has another firm which is in the order in accordance with sorting.
this is because that is the type you would need to itterate through the entries and print them out, but it's easier to just add a break point and look at the values directly.
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
Ok. I understand what you mean. As result i get key and value from Route (for example, if the filter on the Organization List page was set as Firm_Id = 6):
var defaultsValues = table.GetColumnValuesFromRoute(Context);
foreach (var element in defaultsValues)
{
Response.Write(element.ToString());
}
[Firm_Id, 6]
It column Firm_Id is presentedin the EDMin table Organization.
table.EntityType.Name is the name of table Organization.
konstantin.k...
Member
41 Points
22 Posts
Problem with default filtering on Insert.aspx page when inserting new item.
Aug 08, 2011 08:03 AM|LINK
Hello, all.
I am using Dynamic Data 4 and in order to create data model i use ADO.NET Entity Framework.
I have table Organization and table Firms. Table Organization has a references to the Firms table.
First of all, when i am in the Organization List.aspx page i am setting the filter by Firms then i press on DynamicHyperLink and i go on Insert.aspx page, but the DropDownList in the Insert page has another firm which is in the order in accordance with sorting.
Code of Inser.aspx page:
<%@ Page Language="C#" MasterPageFile="~/Site.master" CodeBehind="Insert.aspx.cs" Inherits="WebApplication4.Insert" %> <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"> <asp:DynamicDataManager ID="DynamicDataManager1" runat="server" AutoLoadForeignKeys="true"> <DataControls> <asp:DataControlReference ControlID="FormView1" /> </DataControls> </asp:DynamicDataManager> <h2 class="DDSubHeader"> Add new entry to table <%= table.DisplayName %></h2> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:ValidationSummary ID="ValidationSummary1" runat="server" EnableClientScript="true" HeaderText="List of validation errors" CssClass="DDValidator" /> <asp:DynamicValidator runat="server" ID="DetailsViewValidator" ControlToValidate="FormView1" Display="None" CssClass="DDValidator" /> <asp:FormView runat="server" ID="FormView1" DataSourceID="DetailsDataSource" DefaultMode="Insert" OnItemCommand="FormView1_ItemCommand" OnItemInserted="FormView1_ItemInserted" RenderOuterTable="false"> <InsertItemTemplate> <table id="detailsTable" class="DDDetailsTable" cellpadding="6"> <asp:DynamicEntity ID="DynamicEntity1" runat="server" Mode="Insert" /> <tr class="td"> <td colspan="2"> <asp:LinkButton ID="LinkButton1" runat="server" CommandName="Insert" Text="Insert" /> <asp:LinkButton ID="LinkButton2" runat="server" CommandName="Cancel" Text="Cancel" CausesValidation="false" /> </td> </tr> </table> </InsertItemTemplate> </asp:FormView> <asp:EntityDataSource ID="DetailsDataSource" runat="server" EnableInsert="true" /> </ContentTemplate> </asp:UpdatePanel> </asp:Content>Code of Inser.aspx.cs page:
using System; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Web.DynamicData; using System.Web.Routing; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.Expressions; namespace WebApplication4 { public partial class Insert : System.Web.UI.Page { protected MetaTable table; protected void Page_Init(object sender, EventArgs e) { table = DynamicDataRouteHandler.GetRequestMetaTable(Context); FormView1.SetMetaTable(table, table.GetColumnValuesFromRoute(Context)); DetailsDataSource.EntityTypeFilter = table.EntityType.Name; } protected void Page_Load(object sender, EventArgs e) { Title = table.DisplayName; } protected void FormView1_ItemCommand(object sender, FormViewCommandEventArgs e) { if (e.CommandName == DataControlCommands.CancelCommandName) { Response.Redirect(table.ListActionPath); } } protected void FormView1_ItemInserted(object sender, FormViewInsertedEventArgs e) { if (e.Exception == null || e.ExceptionHandled) { Response.Redirect(table.ListActionPath); } } } }Code of List.aspx page:
...
<div class="DDBottomHyperLink"> <asp:DynamicHyperLink ID="InsertHyperLink" runat="server" Action="Insert"> <img id="Img2" runat="server" src="~/DynamicData/Content/Images/plus.gif" alt="Insert new item" />Insert new item</asp:DynamicHyperLink> </div>...
Any Ideas?
It code i got from csharpbits.notaclue.net.
sjnaughton
All-Star
27308 Points
5458 Posts
MVP
Re: Problem with default filtering on Insert.aspx page when inserting new item.
Aug 08, 2011 08:34 AM|LINK
Hi there, al lot depends on you model but for you information thisline of code
FormView1.SetMetaTable(table, table.GetColumnValuesFromRoute(Context));
is the line that sets the default values and in particular this line
table.GetColumnValuesFromRoute(Context)
get the values from the route
I would debug and do this
var defaults = table.GetColumnValuesFromRoute(Context);
and look at the values being returned and compare to what you expect.
Always seeking an elegant solution.
konstantin.k...
Member
41 Points
22 Posts
Re: Problem with default filtering on Insert.aspx page when inserting new item.
Aug 08, 2011 08:48 AM|LINK
My test on Page_Init:
Results:
But Ajax History works fine in my application.
konstantin.k...
Member
41 Points
22 Posts
Re: Problem with default filtering on Insert.aspx page when inserting new item.
Aug 08, 2011 11:42 AM|LINK
Route in my case when i am trying to insert new item:
<div>http://localhost:56979/Organization/Insert.aspx?Firm_Id=4
</div> </div>sjnaughton
All-Star
27308 Points
5458 Posts
MVP
Re: Problem with default filtering on Insert.aspx page when inserting new item.
Aug 08, 2011 11:47 AM|LINK
Always seeking an elegant solution.
konstantin.k...
Member
41 Points
22 Posts
Re: Problem with default filtering on Insert.aspx page when inserting new item.
Aug 08, 2011 12:46 PM|LINK
Ok. I understand what you mean. As result i get key and value from Route (for example, if the filter on the Organization List page was set as Firm_Id = 6):
var defaultsValues = table.GetColumnValuesFromRoute(Context); foreach (var element in defaultsValues) { Response.Write(element.ToString()); }[Firm_Id, 6]
It column Firm_Id is presented in the EDM in table Organization.
table.EntityType.Name is the name of table Organization.
konstantin.k...
Member
41 Points
22 Posts
Re: Problem with default filtering on Insert.aspx page when inserting new item.
Aug 08, 2011 01:22 PM|LINK
But when we are using the code on Organization List page:
protected void Page_Init(object sender, EventArgs e) { DynamicDataManager1.RegisterControl(GridView1, true /*setSelectionFromUrl*/); table = DynamicDataRouteHandler.GetRequestMetaTable(Context); var defaultValues = Page.GetFilterValuesFromSession(table, table.GetColumnValuesFromRoute(Context)); foreach (var element in defaultValues) { Response.Write(element.ToString()); } GridView1.SetMetaTable(table, defaultValues); GridDataSource.EntityTypeFilter = table.EntityType.Name; }filtering is OK and filter stores in user Session and it work fine.
konstantin.k...
Member
41 Points
22 Posts
Re: Problem with default filtering on Insert.aspx page when inserting new item.
Aug 08, 2011 01:43 PM|LINK
Resolved by adding into ForeignKey_edit.ascx
sjnaughton
All-Star
27308 Points
5458 Posts
MVP
Re: Problem with default filtering on Insert.aspx page when inserting new item.
Aug 08, 2011 05:12 PM|LINK
Glas you sorted :)
Glad your sorted :) read like I was drunk
Always seeking an elegant solution.