Building Data-Driven ASP.NET Web Forms Apps Telerik Software Academy ASP.NET Web Forms.

Slides:



Advertisements
Similar presentations
Windows Basic and Dynamic Disk Borislav Varadinov Telerik Software Academy academy.telerik.com System Administrator Marian Marinov CEO of 1H Ltd.
Advertisements

HTML Forms, GET, POST Methods Tran Anh Tuan Edit from Telerik Academy
Amazon S 3, App Engine Blobstore, Google Cloud Storage, Azure Blobs Svetlin Nakov Telerik Software Academy academy.telerik.com.
RPN and Shunting-yard algorithm Ivaylo Kenov Telerik Software Academy academy.telerik.com Technical Assistant
Telerik School Academy ASP.NET MVC.
Shortest paths in edge-weighted digraph Krasin Georgiev Technical University of Sofia g.krasin at gmail com Assistant Professor.
Telerik Software Academy Telerik School Academy.
Asynchronous Programming with C# and WinRT
Unleash the Power of JavaScript Tooling Telerik Software Academy End-to-end JavaScript Applications.
Nikolay Kostov Telerik Software Academy academy.telerik.com Senior Software Developer and Technical Trainer
Telerik Software Academy Telerik School Academy.
Telerik School Academy ASP.NET MVC.
Character sequences, C-strings and the C++ String class, Working with Strings Learning & Development Team Telerik Software Academy.
Hybrid or Native?! Doncho Minkov Telerik Software Academy Senior Technical Trainer
Done already for your convenience! Telerik School Academy Unity 2D Game Development.
Processing Sequences of Elements Telerik School Academy C# Fundamentals – Part 1.
Welcome to the JSON-stores world Telerik Software Academy Databases.
NoSQL Concepts, Redis, MongoDB, CouchDB
Telerik Software Academy Telerik School Academy Creating E/R Diagrams with SQL Server.
The Business Plan and the Business Model Margarita Antonova Volunteer Telerik Academy academy.telerik.com Business System Analyst Telerik Corporation.
What are ADTs, STL Intro, vector, list, queue, stack Learning & Development Team Telerik Software Academy.
Making JavaScript code by template! Learning & Development Team Telerik Software Academy.
Svetlin Nakov Telerik Software Academy academy.telerik.com Manager Technical Training Who, What, Why?
Access to known folders, using pickers, writing to and reading from files, caching files for future access George Georgiev Telerik Software Academy academy.telerik.com.
Accessing SQL Server and MySQL – Live Demo Svetlin Nakov Telerik Software Academy academy.telerik.com Manager Technical Training
Processing Matrices and Multidimensional Tables Svetlin Nakov Telerik Software Academy academy.telerik.com Technical Trainer
Learning & Development Telerik Software Academy.
Reading and Writing Text Files Svetlin Nakov Telerik Software Academy academy.telerik.com Technical Trainer
Telerik Software Academy ASP.NET Web Forms.
Classical OOP in JavaScript Classes and stuff Telerik Software Academy
Using Selenium for Mobile Web Testing Powered by KendoUI Telerik QA Academy Atanas Georgiev Senior QA Engineer KendoUI Team.
NoSQL Concepts, Redis, MongoDB, CouchDB Svetlin Nakov Telerik Software Academy academy.telerik.com Manager Technical Training
New features: classes, generators, iterators, etc. Telerik Academy Plus JavaScript.Next.
Creating E/R Diagrams with SQL Server Management Studio and MySQL Workbench Svetlin Nakov Telerik Software Academy Manager Technical.
Throwing and Catching Exceptions Tran Anh Tuan Edit from Telerik Software Academy
Telerik Software Academy ASP.NET Web Forms.
Private/Public fields, Module, Revealing Module Learning & Development Team Telerik Software Academy.
Nikolay Kostov Telerik Software Academy Senior Software Developer and Trainer
Telerik Software Academy End-to-end JavaScript Applications.
Planning and Tracking Software Quality Yordan Dimitrov Telerik Corporation Team Leader, Team Pulse, Team Leader, Team Pulse, Telerik Corporation,
Ventsislav Popov Crossroad Ltd.. 1. ASP.NET Data Source Controls  SqlDataSource  EntityDataSource  ObjectDataSource 2. Entity Data Model and ADO.NET.
What you need to know Ivaylo Kenov Telerik Corporation Telerik Academy Student.
Data binding concepts, Bindings in WinJS George Georgiev Telerik Software Academy academy.telerik.com Technical Trainer itgeorge.net.
Pavel Kolev Telerik Software Academy Senior.Net Developer and Trainer
Objects, Properties, Primitive and Reference Types Learning & Development Team Telerik Software Academy.
ORM Concepts, Entity Framework (EF), DbContext
When and How to Refactor? Refactoring Patterns Alexander Vakrilov Telerik Corporation Senior Developer and Team Leader.
Free Training and Job for Software Engineers Svetlin Nakov, PhD Manager Technical Training Telerik Corp. Telerik Software Academy.
Free Training and Job for Software Engineers Svetlin Nakov, PhD Manager Technical Training Telerik Corp. Telerik Software Academy.
Access to known folders, using pickers, writing to and reading from files, caching files for future access George Georgiev Telerik Software Academy academy.telerik.com.
Doing the Canvas the "easy way"! Learning & Development Telerik Software Academy.
Creating and Running Your First C# Program Svetlin Nakov Telerik Software Academy academy.telerik.com Manager Technical Training
Course Overview Doncho Minkov Telerik Software Academy Technical Trainer
Ventsislav Popov Crossroad Ltd.. 1. ASP.NET Data Source Controls  SqlDataSource  EntityDataSource  ObjectDataSource 2. Entity Data Model and ADO.NET.
Data Types, Primitive Types in C++, Variables – Declaration, Initialization, Scope Telerik Software Academy academy.telerik.com Learning and Development.
The past, the present, the future Learning & Development Team Telerik Software Academy.
Connecting, Queries, Best Practices Tran Anh Tuan Edit from Telerik Software Academy
Processing Sequences of Elements Telerik Software Academy C# Fundamentals – Part 2.
Telerik JavaScript Framework Telerik Software Academy Hybrid Mobile Applications.
Telerik Software Academy Databases.
Things start to get serious Telerik Software Academy JavaScript OOP.
Learning & Development Mobile apps for iPhone & iPad.
Processing Matrices and Multidimensional Tables Telerik Software Academy C# Fundamentals – Part 2.
Nikolay Kostov Telerik Software Academy academy.telerik.com Team Lead, Senior Developer and Trainer
Functions and Function Expressions Closures, Function Scope, Nested Functions Telerik Software Academy
Implementing Control Logic in C# Svetlin Nakov Telerik Software Academy academy.telerik.com Manager Technical trainer
Inheritance, Abstraction, Encapsulation, Polymorphism Telerik Software Academy Mobile apps for iPhone & iPad.
Mocking tools for easier unit testing Telerik Software Academy High Quality Code.
What why and how? Telerik School Academy Unity 2D Game Development.
Windows Security Model Borislav Varadinov Telerik Software Academy academy.telerik.com System Administrator
Presentation transcript:

Building Data-Driven ASP.NET Web Forms Apps Telerik Software Academy ASP.NET Web Forms

1. ASP.NET Data Source Controls  SqlDataSource  EntityDataSource  ObjectDataSource 2. Accessing ADO.NET Entity Framework with EntityDataSource  Working with Editable Controls  Master-Details Navigation 3. Model Binding in Web Forms 2

 ASP.NET provides server controls that take care of data binding details  Known as data source controls  SqlDataSource, EntityDataSource, ObjectDataSource, XmlDataSource, …  They are an abstraction over the data source  Data-bound server controls can be associated to a data source control  Through the DataSourceID property 4

 ASP.NET data source controls connect the data- bound controls with the database / ORM:  Typical scenario: 5 Data- Bound Control Data- Source Control ORM Web Form Database GridView control Entity DataS ource Entity Frame- work Web Form SQL Server

 SqlDataSource provides connection to a relational DB (SQL Server, Oracle, OLE DB, …)  Data is manipulated by using commands  Select, Update, Insert and Delete commands  Commands can be either SQL queries or names of stored procedures  Data is processed with a DataSet (by default)  The DataSourceMode property specifies whether to use DataSet or DataReader  Old-fasioned, better use EntityDataSource 6

7 <asp:SqlDataSource ID="DSCategories" runat="server" ConnectionString=" " ConnectionString=" " SelectCommand="SELECT * FROM [Categories]" /> SelectCommand="SELECT * FROM [Categories]" /> <asp:GridView ID="GridViewCategories" runat="server" DataSourceID="DSCategories" DataKeyNames="CategoryID" DataSourceID="DSCategories" DataKeyNames="CategoryID" AutoGenerateColumns="True" AllowPaging="True" AutoGenerateColumns="True" AllowPaging="True" AllowSorting="True"> AllowSorting="True"></asp:GridView>

Live Demo

 The EntityDataSource  Provides data binding in Web applications that use the ADO.NET Entity Framework (EF)  Implements CRUD (create, read, update, and delete) operations  Against a database mapped through EF  On behalf of data-bound controls  Supports complex queries, sorting and paging  The Entity Data Model Designer in VS is used to create the EF mappings (.edmx ) 9

1. Define the Entity Data Model (.edmx ) 2. Put a list control in the form (e.g. ListBox ) 10

3. Bind the ListBox to the data model 4. Select the new "Entity" option in the dialog box 11

5. The VS Designer will then display the available Entity Containers 12

13 <asp:EntityDataSource ID="EntityDataSourceCustomers" runat="server" ID="EntityDataSourceCustomers" runat="server" ConnectionString="name=NorthwindEntities" ConnectionString="name=NorthwindEntities" DefaultContainerName="NorthwindEntities" DefaultContainerName="NorthwindEntities" EntitySetName="Customers" /> EntitySetName="Customers" /> <asp:ListBox ID="ListBoxCustomers" runat="server" DataSourceID="EntityDataSourceCustomers" DataSourceID="EntityDataSourceCustomers" DataTextField="CompanyName" Rows="10" DataTextField="CompanyName" Rows="10" DataValueField="CustomerID" /> DataValueField="CustomerID" />  ListBox control bound an EntityDataSource :

Live Demo Entity Framework

 Master-details navigation could be implemented through filtering: 15 <asp:EntityDataSource ID="DSCustomers" runat="server" EntitySetName="Customers" … /> EntitySetName="Customers" … /> <asp:ListBox ID="ListBoxCustomers" runat="server" DataSourceID="EntityDataSourceCustomers" … /> DataSourceID="EntityDataSourceCustomers" … /> <asp:EntityDataSource ID="DSOrders" runat="server" EntitySetName="Orders" EntitySetName="Orders" <asp:ControlParameter Name="CustID" Type="String" <asp:ControlParameter Name="CustID" Type="String" ControlID="ListBoxCustomers" /> ControlID="ListBoxCustomers" /> </asp:EntityDataSource>

 To access navigational properties in EntityDataSource use " Include "  To use strongly-typed binding ( ItemType ) use EnableFlattening="false" 16 <asp:EntityDataSource ID="DataSourceOrderDetails" ConnectionString="name=NorthwindEntities" ConnectionString="name=NorthwindEntities" DefaultContainerName="NorthwindEntities" DefaultContainerName="NorthwindEntities" EntitySetName="Order_Details" Include="Product" EntitySetName="Order_Details" Include="Product" runat="server" … /> runat="server" … /> <asp:EntityDataSource ID="DataSourceOrderDetails" runat="server" EnableFlattening="false" … /> runat="server" EnableFlattening="false" … />

Live Demo

18 <asp:EntityDataSource ID="EntityDataSourceCustomers" runat="server" ConnectionString="name=…" runat="server" ConnectionString="name=…" DefaultContainerName="NorthwindEntities" DefaultContainerName="NorthwindEntities" EnableInsert="True" EnableUpdate="True" EnableInsert="True" EnableUpdate="True" EnableDelete="True" EntitySetName="Customers"> EnableDelete="True" EntitySetName="Customers"></asp:EntityDataSource> <asp:ListView ID="ListViewCustomers" runat="server" DataKeyNames="CustomerID" DataKeyNames="CustomerID" DataSourceID="EntityDataSourceCustomers"> DataSourceID="EntityDataSourceCustomers"> … … </asp:ListView>

 Editable controls require a two-way binding (data field  UI control)  Use BindItem.Field for strongly-typed binding instead of Item.Field  Use Bind("PropertyPath") for standard binding instead of Eval("PropertyPath") 19 <EditItemTemplate> Company Name: <asp:TextBox ID="TextBoxCompanyName" Company Name: <asp:TextBox ID="TextBoxCompanyName" runat="server" Text=' ' /> runat="server" Text=' ' /> …</EditItemTemplate>

Live Demo Entity Framework

 ObjectDataSource enables data-binding of UI control to collection of objects  Instead of directly binding to a database  Needs a middle-tier business object class  A class providing the Select, Update, Insert, Delete methods (CRUD operations)  ObjectDataSource properties  TypeName – name of the business object class  SelectMethod, UpdateMethod, … 21

22 <asp:ObjectDataSource ID="dsProducts" runat="server" TypeName="ObjectDataSourceProducts" runat="server" TypeName="ObjectDataSourceProducts" SelectMethod="GetAll" InsertMethod="Insert" SelectMethod="GetAll" InsertMethod="Insert" UpdateMethod="Update" DeleteMethod="Delete"> UpdateMethod="Update" DeleteMethod="Delete"></asp:ObjectDataSource> <asp:GridView ID="GridViewProducts" runat="server" DataSourceID="dsProducts" DataKeyNames="ProductID"> DataSourceID="dsProducts" DataKeyNames="ProductID"></asp:GridView> public class ObjectDataSourceProducts { public IEnumerable GetAll() { … } public IEnumerable GetAll() { … } UpdateProduct(Product p) { … } public int UpdateProduct(Product p) { … } …}

1. Define a class to get all files from given folder 2. Add GetAllFiles() method to return a collection of FileInfo objects 23 public class FileSystemManager { public static IEnumerable public static IEnumerable GetAllFiles(string folder) GetAllFiles(string folder) { var files = Directory.GetFiles(folder); var files = Directory.GetFiles(folder); return files; return files; }}

3. Add a ListView control in the form 4. Bind the ListView to the ObjectDataSource 24

5. Next choose your custom class FilesManager 6. And choose the GetAllFiles(…) method as "SELECT Method" 25

7. Click to configure the ListView control 8. Optionally choose layout and style 26

9. Customize the ListView to show only rows you like 10. Add a parameter for the SELECT method 27 <SelectParameters> <asp:Parameter DefaultValue="C:\WINDOWS" <asp:Parameter DefaultValue="C:\WINDOWS" Name="rootFolder" Type="String" /> Name="rootFolder" Type="String" /></SelectParameters>

10. The result is: 28

Live Demo

 LinqDataSource  For LINQ-to-SQL ORM mappings (legacy)  Hierarchical  XmlDataSource  Establishes a connection to an XML source of data (files, documents)  DataFile, TranformFile, XPath  SiteMapDataSource  MS Access – AccessDataSource  Derives from SqlDataSource 30

CRUD Operations Made Easy

 What is "model"?  In data-driven applications "models" are classes that hold the data behind the UI controls  What is "model binding" in ASP.NET?  Bind data controls directly to methods that provide CRUD functionality  SelectMethod  returns IQueryable  SelectMethod  returns IQueryable  InsertMethod, UpdateMethod, DeleteMethod  edit the model (entity) 32

Live Demo

форум програмиране, форум уеб дизайн курсове и уроци по програмиране, уеб дизайн – безплатно програмиране за деца – безплатни курсове и уроци безплатен SEO курс - оптимизация за търсачки уроци по уеб дизайн, HTML, CSS, JavaScript, Photoshop уроци по програмиране и уеб дизайн за ученици ASP.NET MVC курс – HTML, SQL, C#,.NET, ASP.NET MVC безплатен курс "Разработка на софтуер в cloud среда" BG Coder - онлайн състезателна система - online judge курсове и уроци по програмиране, книги – безплатно от Наков безплатен курс "Качествен програмен код" алго академия – състезателно програмиране, състезания ASP.NET курс - уеб програмиране, бази данни, C#,.NET, ASP.NET курсове и уроци по програмиране – Телерик академия курс мобилни приложения с iPhone, Android, WP7, PhoneGap free C# book, безплатна книга C#, книга Java, книга C# Николай Костов - блог за програмиране

1. Create a database holding continents, countries and town. Countries have name, language, population and continent. Towns have name, population and country. Implement an ASP.NET Web application that shows the continents in a ListBox, countries in a GridView and the towns in a ListView and allows master-detail navigation. Use Entity Framework and EntityDataSource. Provide paging and sorting for the long lists. Use HTML escaping when needed. 2. Implement add / edit / delete for the continents, countries, towns and languages. Handle the possible errors accordingly. Ensure HTML special characters handled correctly (correctly escape the HTML). 35

3. Add a flag for each country which should be a PNG image, stored in the database, displayed along with the country data. Implement "change flag" functionality by uploading a PNG image. 4. Write a "TODO List" application in ASP.NET. It should be able to list / create / edit / delete TODOs. Each TODO has title, body (rich text) and date of last change. The TODOs are in categories. Categories should also be editable (implement CRUD). 5. * Write ASP.NET Web Forms application to display in a GridView all tweets from given Twitter user. Load the tweet though the Twitter API. Bind the tweets to the GridView thorugh ObjectDataSource. 36

 "Web Design with HTML 5, CSS 3 and JavaScript" Telerik Academy  html5course.telerik.com html5course.telerik.com  Telerik Software Academy  academy.telerik.com academy.telerik.com  Telerik Facebook  facebook.com/TelerikAcademy facebook.com/TelerikAcademy  Telerik Software Academy Forums  forums.academy.telerik.com forums.academy.telerik.com