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

Model-driven dynamic constraint assignment for automatic insert and update

5 Answers 85 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 26 Mar 2011, 01:44 AM
I'm using the Web Forms RadGrid with an ORM tool that has attributes providing data constraints (required field and other validation rules) as part of its model. What I'm trying to do it come up with a general-purpose way to assign validators to either the in-place editing columns or the automatically generated edit/insert form.

This is a sample of the code I currently have. Based on other examples, I've put it in the pre-render event, but if there's a better event to use for this, I'd be happy to know it. The EntityProperty is the object that allows me to know all the constraints of my entity, which corresponds to a column in a data table. So I'm trying to retrieve the editable item from the RadGrid so I can create and associate the appropriate validator(s) to it based on the validation rules for my entity. How do I get to the editing control for the item in the grid that corresponds to the databound column?

protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        GridTableView tv = RadGrid1.MasterTableView;
        foreach (GridDataItem gdi in tv.Items)
        {
            // the spelunking isn't quite correct yet. Still working on it.
            EntityProperty ep = entityProps.
                    FirstOrDefault(x => x.Name == gdi.EditFormItem.DataItem.ToString());
            if (ep != null)
            {
                gdi.ID = gdi.ID;
            }
        }
        tv.Rebind();
    }
}

TIA for any tips that lead me in the right direction. I hope my request is clear.

Follow-up: I just found these posts related to Entity Framework 4 and MVC that talk about the same way I want to use model-driven validation. http://stackoverflow.com/questions/4915957/using-system-componentmodel-dataannotations-with-entity-framework-4-0/ and http://ryanhayes.net/blog/data-annotations-for-entity-framework-4-entities-as-an-mvc-model/.

If this isn't a common request, it should be. If it isn't a planned feature for Telerik, it should be.

5 Answers, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 31 Mar 2011, 09:43 AM
Hi John ,

I noticed you have already opened a support ticket on this subject. If you do not mind we will continue the communication there. I am also posting the response here for anyone else interested.

Could you please verify that you use the RadGrid for ASP.NET AJAX, because the ajax RadGrid is a different than the Telerik MVC Grid. Additionally the RadGrid for ASP.NET AJAX does not support DataAnnotations. However you could add dynamically the validation controls to an edit field in Telerik RadGrid . Please check out the following article which explain how to add a validator of your choice to the edit field:
http://www.telerik.com/help/aspnet-ajax/grid-validation.html

Greetings,
Marin
the Telerik team
0
John
Top achievements
Rank 1
answered on 31 Mar 2011, 11:08 PM
Thanks, I posted the support ticket after no one suggested anything here for 3 days. I'm definitely happy to share whatever is the resolution on the forum so others can benefit from it as well. I'm very suprised I appear to be the only person asking for this. Has everyone else chosen to use the MVC grid for doing this type of model-driven architecture?
0
Marin
Telerik team
answered on 01 Apr 2011, 11:23 AM
Hello John ,

The MVC and ASP.NET frameworks have quite different validation infrastructures and mixing them together might require a great deal of customization effort in order to tailor the model-driven validation to the needs of ASP.NET.

Greetings,
Marin
the Telerik team
0
John
Top achievements
Rank 1
answered on 09 Apr 2011, 06:30 AM
Marin,

Thanks. I'm aware of their validation infrastructure differences. Nevertheless, both have validation infrastructures that share many similar traits.

It occurs to me that a 3rd party vendor, particularly one like Telerik that even offers an ORM, could greatly benefit from provding model-driven validation for all user interfaces they support in their components, and have a distinct competitive advantage.
0
Marin
Telerik team
answered on 11 Apr 2011, 08:05 AM
Hi John ,

Thank you for the suggestion. We appreciate your feedback.

All the best,
Marin
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
John
Top achievements
Rank 1
Answers by
Marin
Telerik team
John
Top achievements
Rank 1
Share this question
or