This is a migrated thread and some comments may be shown as answers.

Custom parsing while data binding with entity framwork

2 Answers 65 Views
Grid
This is a migrated thread and some comments may be shown as answers.
OBollmann
Top achievements
Rank 2
Iron
OBollmann asked on 22 Mar 2009, 09:56 PM
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 Answers, 1 is accepted

Sort by
0
OBollmann
Top achievements
Rank 2
Iron
answered on 23 Mar 2009, 12:38 PM
No idea anybody?

Oliver
0
Tsvetoslav
Telerik team
answered on 25 Mar 2009, 12:01 PM

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.
Tags
Grid
Asked by
OBollmann
Top achievements
Rank 2
Iron
Answers by
OBollmann
Top achievements
Rank 2
Iron
Tsvetoslav
Telerik team
Share this question
or