Custom parsing while data binding with entity framwork

3 posts, 0 answers
  1. OBollmann
    OBollmann avatar
    14 posts
    Member since:
    Jan 2007

    Posted 22 Mar 2009 Link to this post

    Hi there,

    I developed some projects with entity framework up till now - so my skills with this technology (WPF/WinForms) are quiet good. But I'm rather new to ASP.net. In WinForms there are two events for data binding "Parse" and "Format" and in WPF we have custom implemented IValueConverts. But what ways are there in ASP.net (not MVC)?!?

    I successfully attached an EntityDataSource to a RadGrid. Inserts/Updates/Deletes are working as expected! But trying to implement some piece of user defined value parsing drives me crazy!

    For an example I give you the following column definition:

    <

     

    EditItemTemplate>

     

    <asp:TextBox ID="TextBoxPrice" Text='<%# Bind("Price", "{0:#.00} €") %>' runat="server"></asp:TextBox>
    </EditItemTemplate>

    As you can see, there is a value from the data source (property 'Price') bound with formating information to an appropriate TextBox control. But when I try to update - of course - the operation fails. The string "10,00 €" could not be parsed as an numeric value. Now I would expect an event wich gives me the instance of the current bound item or a value that I can change - anything to customized changing string "10,00 €" to "10,00" or custom filling values to the object. But I can't find anything related :-S

    Am I missing something here???

    Best regards,
    Oliver

     

     

  2. OBollmann
    OBollmann avatar
    14 posts
    Member since:
    Jan 2007

    Posted 23 Mar 2009 Link to this post

    No idea anybody?

    Oliver
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 25 Mar 2009 Link to this post

    Hello OBollmann,

    The easiest way is to attach an event handler to the OnUpdating event of the entity data source, get a reference to the entity being updated, cast it to the corresponding entity type and change the price field. For example, if your entity data model is called NorthwindModel and you have a Products entity, your code should become as follows:

        protected void EntityDataSourceCustomers_Updating(object sender, EntityDataSourceChangingEventArgs e)  
        {  
            ((NorthwindModel.Customers)(e.Entity)).Price = /*your custom conversion logic comes here*/;  
        } 

    I hope this helps.

    Sincerely yours,

    Tsvetoslav
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Back to Top