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?
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.
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)
{
// from http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/usercontroleditform/defaultcs.aspx
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.