Your SlideShare is downloading. ×
Work with data in ASP.NET
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

Work with data in ASP.NET

2,592
views

Published on

Goal: Bringing data to the web and back :-) …

Goal: Bringing data to the web and back :-)
Old Style
New Style
DataBinding
DataGrid
Input Validation

Published in: Education

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
2,592
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
60
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • Click to add notesPeter Gfader Developing Windows and Web applications
  • Request ResponseOpen browser and browse around
  • Goal: Show View data to users on the webLet users enter and modify data
  • Show how easy it isHow many code lines did i write?Show them the old wayHuge difference!
  • Changes to Datasource get forwarded to databaseChanges from database get forwarded to data grid
  • Property DataSource and DataMember on grid
  • Show controls in VSDataList = More for List layout (http://msdn.microsoft.com/en-us/magazine/cc301328.aspx )DetailsView = mainly for editing (row/col switched) 1 record at a timeFormView = like detailsview but more control over html rendered code (layout) that’s goodListView = like datalist but more control again, see EA emp Repeater = same as Listview, Listview replaces repeaterDropDownListListBox = simple list of itemsCheckBoxListRadioButtonList
  • Go to website: telerikTelerik RAD ControlsComponent ArtInfragisticsDevexpressJanus
  • Suggest or common ones are querystring, hidden fieldCookies saving bits of info for all pagesE.g. Select a row from the grid and show the details in a DetailsViewPass the selected row’s ID (e.g. ContactID) as a query string parameterE.g. http://localhost:1234/MyWebApp/Details.aspx?ContactID=1
  • Show url with IDPostback http://www.search-cube.com/
  • Problem Exists Between Chair and ComputerClient database SWIFT project
  • ASP.NET existing Validation controls create client side script for us
  • CustomValidator Method Validate write your own code there (SERVER SIDE)
  • Transcript

    • 1. Developing Windows and Web Applications using Visual Studio.NET
      Eric Phan
      Solution Architect
    • 2. Homework?
      • Address Control
      • 3. Credit Card Validation
    • http://sharepoint.ssw.com.au/Training/UTSNET/
      Part 2: .NET Webforms
      Overview of .NET Webforms
      Data in Webforms TODAY
      Usability
      Rich Web Forms and
      Other ASP.NET Features
      Web Security
      Advanced Topics & Future Technology (Silverlight)
      Webforms
    • 4. Recap
    • 5. 1
      2
    • 6.
    • 7. Session 7: Data in the Web
      • Goal: Bringing data to the weband back :-)
      • 8. Old Style
      • 9. New Style
      • 10. DataBinding
      • 11. DataGrid
      • 12. Input Validation
    • Data in our database
    • 13. Data
    • 14. Bring database to the web
      Show/view
      Data
      Enter
    • 15. OLD way
    • 16. What is ADO.NET?
      Set of classes that expose data access services to the .NET programmer
      ADO.NET provides a rich set of components for creating distributed, data-sharing applications
      It is an integral part of the .NET Framework, providing access to relational data, XML, and application data
    • 17. WebForm Apps
      WinForm Apps
      ADO.NET
      DataSets
      SQLConnection
      SQLCommand
      SQLDataAdapter
      SQLDataReader
      SQL Data Providers
      SQL Data
      XML Data
      Oracle Data

    • 18. Objects
      Instead of DataSets we use classes
      Extensible
      Can embed logic and validation
      A more OO approach
    • 19. WebForm Apps
      WinForm Apps
      Objects/Entities
      Data Sources
      SQL Data
      XML Data
      Oracle Data

    • 20. DataSets or Business Objects
      Why use DataSets
      A highly functional container for data that can be strongly typed
      Automatic change tracking for contained data
      Seamless data-binding support
      Why Use Objects
      Business Objects (NHibernate, NTiers, LINQ to SQL, LINQ to Entities)
      Light weight
      Good data-binding support
      Extensible and OO
      Very easy to use
      No SQL command Strings
    • 21. The new way!LINQ 2 EntitiesLINQ 2 SQL
    • 22. LINQ to SQL/Entities
      Brand new in the .NET 3.5 Framework
      Easily access and query your database through classes
      Logical access to class hierarchies
      Supports Inheritance
      Intuitive to use
    • 23. DBML File
      Database Mapping Language
      Contains a mapping of classes to database tables
      Has built in logic to handle selection, updates and deletes
      Can be customized
      www.hookedonlinq.com
    • 24. var customers = from c in db.Customers
      where c.FirstName.StartsWith(“A”) select c
      SQL Syntax
    • 25. var customers = db.Customers.Where(c => c.FirstName.StartsWith(“A”);
      Lambda Syntax
    • 26. Challenge, use this instead of SQL Server Management Studio for a month
      LINQPad
    • 27.
    • 28. See our Rules
      http://www.ssw.com.au/ssw/Standards/Rules/RulesToBetterLINQ.aspx
    • 29. Databinding
    • 30. Bind the data
      Data
      Data source
    • 31. Data Binding
      Data
      Data source
      From MSDN: Data binding is the process that establishes connection between the application UI and business logic
      Binding controls to data from database
      Bind a grid on Webform to a database table
      Simple, convenient, and powerful way to create a read/write link between the controls on a form and the data in their application
    • 32. Databinding the GridView (code)
      C#
      NorthwindDataContext db = newNorthwindDataContext();
      GridView1.DataSource = db.Customers;
      GridView1.DataBind();
      English
      Instantiate our data access class
      Make the datasource of GridView1 all the customers from our database
      Bind the Grid
    • 33. Databinding the GridView (designer)
    • 34. Databinding the GridView (designer)
    • 35. Databinding the GridView (designer)
    • 36. Databinding the GridView (designer)
    • 37. Databinding the GridView (designer)
    • 38. Databinding the GridView (running)
    • 39. GridView
      • Select sort and edit
      • 40. Display a Table from a Database
      • 41. Easy to configure
      • 42. Without writing any code at all
    • GridView
      Lots of built in features like:
      Sorting
      Paging
      Inserting
      Updating
      Deleting
      Selecting
    • 43. Enabling these features
      Enable Delete, Insert, Update on the DataSource
    • 44. Enabling these features
      Enable them on the GridView
    • 45. Easy!
    • 46. Other Data Bindable Web Controls
      Bindable to Lists
      DataList
      DetailsView
      FormView
      Repeater/ListView
      DropDownList
      ListBox
      CheckBoxList
      RadioButtonList
      Bindable to Properties/Columns
      Most other controls
    • 47. Data-Bound Controls
      Most controls in .NET Framework support data binding
      Controls inherit from the WebControl base classwhich implements IDataBindingsAccessorinterface
      Important Data-binding properties
      DataSource
      DataMember
      DisplayMember
      ValueMember
      Design your own controls or purchase 3rd party controls
    • 48. Passing Parameters
    • 49. Passing Parameters between pages
      Pass parameters to pages or controls
      Pass parameters to our data sources
      Parameters can be obtained from:
      Query String
      Session Variable
      Control Property
      Hidden Field
      Cookie
    • 50. 1. Create a CustomerDetails.aspx
      Add a Details View and create a new Datasource
    • 51. 2. Create a LINQ Data Source
    • 52. 3. Specify the Where clause
    • 53. 4. Make it read from the Query String
    • 54. 5. Change the Select on the GridView to Link to the CustomerDetails Page
    • 55. 6. Edit the templates
    • 56. 7. Delete Select and Add a Hyperlink
    • 57. 8. Configure the Hyperlink
      CustomerDetails.aspx?CustomerID={0}
    • 58. Run it
    • 59. Validation – Don’t trust anyone
    • 60. Validation - Bring database to the web
      Show/view
      Data
      Enter
    • 61. Validation
      Why do we need it?
      PEBCAC
      Bad Data
    • 62. Input Validation
    • 63. Why use Validations?
      Seamless verification of data fields
      Check for mandatory fields
      Check for correct data formats
      Check for data ranges
      Reduces incorrect data entered into your database
      Prevent possible runtime exceptions
    • 64. Validation Types
      Client
      Show/view
      Data
      Enter
      Client
      Server
    • 65. Validation Types
      Client-Side Validation
      Validations are performed before the form is posted back
      Quick and responsive for the end user
      Insecure
      Server-Side Validation
      Validation checks are performed on the server
      Secure because these checks cannot be easily by passed
      Sometimes can be slow
      Recommendation
      Use both the types
      This approach provides the best of both worlds
      Client
      Show/view
      Data
      Enter
      Client
      Server
    • 66. ASP.NET Validation Server Controls
      RequiredFieldValidator
      CompareValidator
      RangeValidator
      RegularExpressionValidator
      CustomValidator
      ValidationSummary
    • 67. To put the Northwind database up on the web?
      CRUD for all tables
      Pages for all tables
      Validation
      So how long do you think it would take...
    • 68. 1 line of code
      5 Minutes
    • 69. Awesome starting point
      Learn more from http://www.asp.net/dynamicdata/
      ASP.NET Dynamic Data
    • 70. Extend what’s given to you and you can make really great websites
      You can use it as a framework
    • 71.
    • 72. Any issues ... questions
      PeterGfader@ssw.com.au
      EricPhan@ssw.com.au
    • 73. Thank You!
      Gateway Court Suite 10 81 - 91 Military Road Neutral Bay, Sydney NSW 2089 AUSTRALIA
      ABN: 21 069 371 900
      Phone: + 61 2 9953 3000 Fax: + 61 2 9953 3105
      info@ssw.com.auwww.ssw.com.au
    • 74. Resources
      www.hookedonlinq.com
      http://www.asp.net/get-started/
      http://weblogs.asp.net/scottgu/
      http://www.asp.net/dynamicdata/
      If you have the next awesome web ideahttp://www.microsoft.com/BizSpark/
      http://www.ssw.com.au/ssw/Standards/Rules/RulesToBetterLINQ.aspx