Dynamic Data in Regular Websites/Web Applications
2013-06-09 12:19
309 查看
http://weblogs.asp.net/davidfowler/archive/2009/05/06/dynamic-data-preview-4.aspx
Update:DavidEbbohasagreatvideoonchannel9aboutthis.Youcanwatchit
TodayI'mexcitedtosharethatwe'vereleasedDynamicDataPreview4oncodeplex.Checkoutthelatestbitshere.
ThisreleaseisparticularlyinterestingnotonlyforpeoplethathavebeenusingDynamicDataforawhilenow,butanyonethathasanexistingapplicationtodaywhowantstousesomeofthenicetiesDynamicDataofferswithouthavingtotakeallthejunkassociated.
TakealookattheSimpleDynamicDataprojectforexamples.
ExistingSites
Hereare2goodreasonstouseDynamicData:
Richmodelvalidation
RichtemplatingsupportviaFieldTemplates
Ifyou'veeverwrittenadatadrivenappinwebformsusingourdatacontrols,youwouldhaverealizedthatwearelackingalotwhenitcomestovalidation.Youcanenableallofthisgoodnesswithamagicextensionmethod.
Note:ThemethodrequiresthatyoupassinthetypethatmayhaveannotationsinorderforustoreadMetadata.Ifyou'renotfamiliarwiththewayannotationsworkinDynamicDatathenwatchthevideoshere.
ThismethodcallenablesDynamicControl/DynamicFieldtoworkwithinanyofthedatacontrolswhichmakesuseofFieldTemplates,
andenablestherichvalidationsupport.
Makingitwork
Soweknowaboutthismagicmethodcallandsomehowcallingitwithatypemakesitalljustwork.Let'swalkthroughanexampleofhowwewouldusethis.Hereismymodel:
Thisisthetypewearegoingtouseformetadata.UsingtheattributesfromSystem.ComponentModel.DataAnnotationswecanadduseful
annotationstoourmodelthatwillbeusedforvalidationanddisplayformatting.AddingtheseattributesallowsDynamicDatatoenabletheappropriatevalidator.i.eRangeValidator,RequiredFieldValidatoretc.
Nowwe'regoingtoenablethisonourGridViewusingthesamemethodcallasaboveinconjunctionwithanObjectDataSourcetocompleteour
application:
Markup
Note:DynamicDatatakescareoftheMetadatanotthedata.Youstillneeddatabindthedatacontrolagainstsomedatasource/datasourcecontrol.
Herearetheresultswhenweareediting:
Asyoucansee,theattributeswespecifiedonourStudentclassdirectlyaffectthegridandvalidationisenabled.
There'smorecoolstufftotalkaboutbutI'llmentionthoseinupcomingposts.Fornow,downloadthepreviewandreaduponDynamicData!
PublishedWednesday,May06,20096:33PMbydavidfowl
DynamicDatainRegularWebsites/WebApplications
Update:DavidEbbohasagreatvideoonchannel9aboutthis.Youcanwatchithere.
TodayI'mexcitedtosharethatwe'vereleasedDynamicDataPreview4oncodeplex.CheckoutthelatestbitsThisreleaseisparticularlyinterestingnotonlyforpeoplethathavebeenusingDynamicDataforawhilenow,butanyonethathasanexistingapplicationtodaywhowantstousesomeofthenicetiesDynamicDataofferswithouthavingtotakeallthejunkassociated.
TakealookattheSimpleDynamicDataprojectforexamples.
ExistingSites
Hereare2goodreasonstouseDynamicData:
Richmodelvalidation
RichtemplatingsupportviaFieldTemplates
Ifyou'veeverwrittenadatadrivenappinwebformsusingourdatacontrols,youwouldhaverealizedthatwearelackingalotwhenitcomestovalidation.Youcanenableallofthisgoodnesswithamagicextensionmethod.
protectedvoidPage_Init(){
GridView1.EnableDynamicData(yourtypehere);
}
Note:ThemethodrequiresthatyoupassinthetypethatmayhaveannotationsinorderforustoreadMetadata.Ifyou'renotfamiliarwiththewayannotationsworkinDynamicDatathenwatchthevideos
ThismethodcallenablesDynamicControl/DynamicFieldtoworkwithinanyofthedatacontrolswhichmakesuseof
andenablestherichvalidationsupport.
Makingitwork
Soweknowaboutthismagicmethodcallandsomehowcallingitwithatypemakesitalljustwork.Let'swalkthroughanexampleofhowwewouldusethis.Hereismymodel:
publicclassStudent{
[Required]
[Range(0,100)]
publicintAge{get;set;}
[Range(0.0,4.0)]
publicdoubleGPA{get;set;}
[Required]
publicstringFirstName{get;set;}
[Required]
publicstringLastName{get;set;}
[DisplayFormat(DataFormatString="{0:d/M/yyyy}")]
publicDateTimeBirthDate{get;set;}
}
Thisisthetypewearegoingtouseformetadata.Usingtheattributesfrom
annotationstoourmodelthatwillbeusedforvalidationanddisplayformatting.AddingtheseattributesallowsDynamicDatatoenabletheappropriatevalidator.i.eRangeValidator,RequiredFieldValidatoretc.
Nowwe'regoingtoenablethisonourGridViewusingthesamemethodcallasaboveinconjunctionwithanObjectDataSourceto
application:
protectedvoidPage_Init(){
GridView1.EnableDynamicData(typeof(Student));
}
Markup
<asp:GridViewID="GridView1"runat="server"DataSourceID="ObjectDataSource1"AutoGenerateEditButton="true">
</asp:GridView>
<asp:ObjectDataSourceID="ObjectDataSource1"runat="server"
DataObjectTypeName="Student"DeleteMethod="DeleteStudent"
InsertMethod="InsertStudent"SelectMethod="GetStudents"
TypeName="StudentsRepository"UpdateMethod="UpdateStudent">
</asp:ObjectDataSource>
Note:DynamicDatatakescareoftheMetadatanotthedata.Youstillneeddatabindthedatacontrolagainstsomedatasource/datasourcecontrol.
Herearetheresultswhenweareediting:
Asyoucansee,theattributeswespecifiedonourStudentclassdirectlyaffectthegridandvalidationisenabled.
There'smorecoolstufftotalkaboutbutI'llmentionthoseinupcomingposts.Fornow,downloadthepreviewandreaduponDynamicData!
PublishedWednesday,May06,20096:33PMby
相关文章推荐
- Web Data Mining and Applications in Business Intelligence and Counter-Terrorism
- Plug-In Hybrids: ASP.NET WebForms and ASP.MVC and ASP.NET Dynamic Data Side By Side
- SharePoint At Work----Hyperlinks in the Data View Web Part
- spring.data.jpa.query :Cannot use native queries with dynamic sorting and/or pagination in method
- SPRING IN ACTION 第4版笔记-第九章Securing web applications-007-设置LDAP server比较密码(contextSource、root()、ldif()、)
- ecshop建站问题:Strict Standards: Redefining already defined constructor for class alipay in /data/web/in
- visual event recognition in videos by learning from web data
- eclipse dynamic web error——tomcat server not start with in 45 sec
- SharePoint At Work----Hyperlinks in the Data View Web Part
- Dynamic Setting ImageUrl In DataPager
- Manual JSON serialization from DataReader in ASP.NET Web API
- SPRING IN ACTION 第4版笔记-第五章BUILDING SPRING WEB APPLICATIONS-006-处理表单数据(注册、显示用户资料)
- Programming dynamic ALV in WebDynpro for ABAP
- Solving “Dynamic Web Module 3.0 requires Java 1.6 or newer” in Maven Projects
- [导入]ASP.NET 3.5 Extensions: Dynamic Data Web Site 要點整理
- ASP.NET 3.5 Extensions: Dynamic Data Web Site 要點整理(转载)
- visual event recognition in videos by learning from web data
- Vulnerabilities in SWFUpload in multiple web applications: WordPress, Dotclear, InstantCMS, AionWeb
- W3C 用于在 web 应用中处理文件的 API(W3C File API for representing file objects in web applications)
- Data Transfer between Business and Data Access Components in Enterprise Applications using .Net