c# - using asp.net data source to bind to controls vs binding controls to a context -
ok straight out of college , 1 month first developer job. in school have taught if use toolbox in asp.net (c#) makes things quicker , have less code type using drag , drop controls. have bind controls data source put on page. understand , know inside controls , data source can customize way acts or data brings , can bind these based off of other controls , things well. @ new job have told me stay away using drag , drop controls , code them hand used coding , learn more go can see , agree on.
but told me not use data source controls tool box use this:
protected void page_load(object sender, eventargs e) { populatedropdownlist(); } private void populatedropdownlist() { ilist<company> companies = null; using (var context = new companycontext()) { companies = context.companyrepository.tolist(); } ddcompanyname.datatextfield = "name"; ddcompanyname.datavaluefield = "id"; ddcompanyname.datasource = companies; ddcompanyname.databind(); }
the drop down box using named "ddcompanyname". in example instead of using data source control data in form use method calls/uses context. told when first starting build program 5-6 years ago sub-contracted out part of work , guy worked said not use data source controls bind data. use lot of telerik controls , custom things in application.
my question is: 1 way better other? have more control binding through method context? more secure bind without data source control?
Comments
Post a Comment