locked
Populating Entity Templates RRS feed

  • Question

  • User-326746839 posted

    Hi,

    It sems that sometimes the theoretical aspects of programming complex ASP.Net DD algorithms make the process of giving/obtaining answers from experts a quite difficult experience. mNot juicy at all !

    For me, it will be asier sometimes just getting straightforward, simple explanations of "where" and "how" some things happen inside DD

    I'd simply like to know how to gather the data (that will be shown on screen or thas is being showed on screen) at the right data in proper time.

    For instance, in Oleg Sych's blog http://www.olegsych.com/2010/09/understanding-aspnet-dynamic-data-entity-templates/ "Understanding ASP.NET Dynamic Data: Entity Templates" you can see the following Custom Entity Template filled with data:

    From my point of view, despite of how all of this might be accomplished inside DD I'd like to know better "How" and "Where" to collect this data and make use of it in my own code so I might be able to do some basic programming stuff like: passing data between controls to do cascading. I guess I'd like to do some calculations on the fly as to fill some custom fields inside that form,

    In general, USE ALL THE DATA THAT WILL BE USED TO DISPLAY THIS FORM .... in my own way. Despite of all technical exsplanation on how DD works I'd rather like not to understand all intrincacies of complex framework programming but use data (as we programmers of the 3rd world noramlly do) to do all our simple programming stuff like looping, passing data, making calculations, showing popup screens, and so on.

    I don't know how to explain what I want (maybe because of the usage of my own native speaking Spanish language) but if I were to do some cascading I'd like to do it on the fly (I don't wnat to do custom things for every page because otherwise I'd rather be using a simpel web forms applciation in the old fashioned way, isn't it)

    I'd like to make some iterations though the MetaData file as to get all correct info to be displayed (fields, foreign keys in its proper ordering, etc) so I can get for instance the data coming from the firts FK (Let's say Countries) and get code "223345" as part of user selection on a DropDownList) belonging to "USA" and pass that value to the next control (another DropDownList) in which Iwill select only those "States" belonging to the previously selected "Country" and then pass this two values (let's say Country = "223345" and State "" e.g.: "Illinois") so I can show the next DropDownList correctly: Cities of Illinois, USA. 

    I know you can say that I can customize BUT DD isn't supposed to be doing customizing as the rule but the exception of it, ... or is it?

    Is this kind of approach too rough or non-elaborated, childish maybe ??????

    Carlos N. Porras
    (El Salvador)

    Monday, March 17, 2014 12:22 AM

Answers

  • User-330204900 posted

    Hi Carlos, sorry I was busy, what I think you want is a change aware field template, this is where one field template notifies any others that have subscribed that it has changed.

    Does that sound like it?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 19, 2014 9:01 PM

All replies

  • User-330204900 posted

    Hi Carlos, if you did this the old fashond way (i.e. standard WebForms) where would you find the data? Would you parse the ForView/Details view to extracts the data? How would you be trying to achive that? Because it's the same for DD as DD is only webForms with User Controls for the most part, so the same techniques apply here. Withh DD the actual data int he FormView is just wrapped in a few more controls is all.

    P.S. I'm not trying to be awkward :) if you can point me as to how you woudl have done it before DD then I will try and show you how to use you knowlede to do the same in DD :)

    Monday, March 17, 2014 4:10 AM
  • User-326746839 posted

    As usual ... Thanks a lot Steve for your valuable timne and effort in trying to understand me !!

    I'll make my question a lot simpler. I'll take this form as a sample for asking.... 

    Please forget about anything else. This is just a very simple sample to formulate a very simple, very basic question.

    If I had use Asp.Net Dynamic Data to build the form that is shown there in the example ... (please, forget how it was built, it doesn't matter. I just need the image as an output sample).... I'd like to know how to capture the data that is currently shown for each of the controls : an ID number and the text or number or date shown.

    This is how is done in standard web forms:  The example displays a 2 level cascading because the form has been customized for having 2 dropdownlist controls ... you are no supposed to do that in DD !!!! It will be rendered properly according to the MetaData data, isn't it?

    In a normal ASP.Net DD situation, the 2 dropdownlists will be displayed but the second one won't be filtered depending on previously "category" selection

    So I'd like to do some things with the data that fills the form ... before it renders each one of its controls ,,, is that possible at all?

    I know this is a real piece of cake once you have understood me ... !!!! But my english way of saying it seems to be absolutelly WRONG !!!!

    Carlos N. Porras
    (El Salvador)

    Monday, March 17, 2014 9:56 PM
  • User-330204900 posted

    Hi Carlos, your english is as good as mine and I was borne in England :) not translationg concepts that's hard. So let me see if I get what you mean, you have two dropdown lists yest and you want to filter the second based on the selection made in the first, yes? is so I already have a solution for this and it can be doen two ways:

    1. My Classic Cascading Filters and Field Templates on NuGet
    2. Part 1 – A Cascading Hierarchical Field Template & Filter for Dynamic Data
    Tuesday, March 18, 2014 5:59 AM
  • User-326746839 posted

    Ok .... I withdraw this post ....

    Hi Steve,

    Your cascading is ok but that is not what I'm looking for here !!

    Let's put a simple example of what I'd like to do (a hypothetical example) 

    1)       I have 5 different mileage payment scales for my sales people

    2)       Those scales vary depending on where they are going

    3)       Depending on the selected place, I have to make adjustments to the gasoline price as it varies in a very funny way depending on what city are you going to travel and also depending on the nature of the geographical area (mountains, very inclined slopes, bas state of the road, type of rocks and soil, etc)

    So I'd like to have my DD app working in a way in which I can get from the cascade of dropdownboxes the name and code of the country, code and name of the city and also code and name of the town. I want to have that data available to do whatever I'd like in my source code. 

    Depending on the city chosen I'd like to make an adjustment to the monetary figures involved in the trip.

    So I will seek in a table the kilometers of distance between two cities (on the route) ... as in many cities as the driver will go.

    So I need to go making the sum of the kilometers that are to be run by the truck in every route

    Tthat also will involve what roads the driver will take to go from city to city (sometimes there will be more than one)

    Then I have to check the list of gas prices for that week (it varies in our country every two weeks)

    So I'll be doing your cascading for each one of them and I need to go storing the results in someplace so I can make the rights sums 

    I know that a huge design and a huge system might accomplish to do these tricks very easily but sometimes you are not allowed to spend time and money in building robust applications.

    Sometimes you just need to pass the data to your accountant so he can do easily all the tricks in a simple spreadsheet ….. and it works just fine !

    So my original question rises again: (I know I look like a kindergarten kid asking this) 

    How can I gather the data that is going to be displayed by each one of the controls that are going to be displayed in the UI screen (in the form)?

    I don’t really mind how DD does this. I just need to know in DD where and how can I collect that data …

    And it will be very nice to know how to collect all the data displayed in a GridView ….

    That will be wonderful !!!!!!

     

    Carlos N. Porras
    (El Salvador)

    Tuesday, March 18, 2014 8:07 PM
  • User-330204900 posted

    Hi Carlos, sorry I was busy, what I think you want is a change aware field template, this is where one field template notifies any others that have subscribed that it has changed.

    Does that sound like it?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 19, 2014 9:01 PM
  • User-330204900 posted

    Hi Carlos, have look at this post of mine, it's a start: Communicating Between FieldTemplates in Dynamic Data I am waiting for SideWaffle template to include the actual Side Waffle template to put my FULL Project together and put on the Visual Studio Gallery.

    Friday, March 21, 2014 5:04 AM
  • User-326746839 posted

    Hi Steve,

    In Model Binding in ASP.NET 4.5 Web Forms http://weblogs.asp.net/dwahlin/archive/2013/04/02/asp-net-4-5-web-forms-features-model-binding.aspx

    Dan Wahlin shows this example: 


    and the code goes more or less like this:

    <asp:DropDownList ID="CustomersDropDown" runat="server" AutoPostBack="True" 
        SelectMethod="BindCustomers"
        AppendDataBoundItems="true"
        DataTextField="FullName" DataValueField="CustomerID">
        <asp:ListItem Value="0">Select One:</asp:ListItem>
    </asp:DropDownList>
    public IQueryable<Customer> BindCustomers()
    {
        var custs = from cust in _DbContext.Customers
                    join order in _DbContext.SalesOrderHeaders on cust.CustomerID equals order.CustomerID
                    orderby cust.LastName
                    select cust;
            return custs;
    }
    <asp:ListView ID="OrdersListView" runat="server" 
        ItemType="ModelBinding.Data.SalesOrderHeader"
        DataKeyNames="SalesOrderID"
        SelectMethod="BindOrders"
        UpdateMethod="UpdateOrder"
        InsertMethod="InsertOrder"
        DeleteMethod="DeleteOrder">
    
       Templates go here
    
    </ListView>

    AND THE MORE INTERESTING PART GOES HERE:

    public IQueryable<SalesOrderHeader> BindOrders([Control("CustomersDropDown")] int? customerID)
    {
        var orders = from c in _DbContext.SalesOrderHeaders
                        where c.CustomerID == customerID
                        orderby c.OrderDate
                        select c;
        return orders;
    }

    Steve, if I were to combine your solution Communicating Between FieldTemplates in Dynamic Data  with this approach, how could I make the previous code "generic" so instead of having to write "CustomersDropDown" I could have the name from the MetaData that DD is currently using at that specific moment and instead of " int? customerID " I could also gather that data from MetaData too.

    That will be the solution to my question


    Carlos N. Porras
    (El Salvador)


    zdvxczv

    Saturday, March 22, 2014 9:43 PM
  • User-330204900 posted

    Hi Carlos, my template woudl just work with this the model binding does not matter as the communication is between field template and the only caveat is that the sender appears before the recived in the control list.

    Sunday, March 23, 2014 3:10 PM
  • User-326746839 posted

    Hi,

    I understand it can be done. I was asking "how" !! Is not really simple .... quite the contrary 

    Best regards

    Carlos N. Porras
    (El Salvador)

    Sunday, March 23, 2014 10:15 PM
  • User-330204900 posted

    Sorry Carlos, what I meant was if you are using that kind of Binding my field template will just work they are agnostic of the data model type or binding type. It's just events :)

    Take the sample I posted and add that to your project and it will just work :)

    Tuesday, March 25, 2014 9:37 AM