1 / 20

CSCI 6962: Server-side Design and Programming

CSCI 6962: Server-side Design and Programming. Data Viewing and Editing Tools in ASP. GridView. Basic tabular display Also simple field editing Basic steps: Create new SqlDataSource (as before) Drag in a GridView Set its Data Source. GridView. GridView now bound to database

foster
Download Presentation

CSCI 6962: Server-side Design and Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSCI 6962: Server-side Design and Programming Data Viewing and Editing Tools in ASP

  2. GridView • Basic tabular display • Also simple field editing • Basic steps: • Create new SqlDataSource(as before) • Drag in a GridView • Set its Data Source

  3. GridView • GridView now bound to database • By default, shows all fields in table form

  4. GridView Editing • Can edit which fields shown and their format • Edit columns • Choose field to edit and manipulate its properties

  5. GridView Editing • Example: • Make ISBN not visible (set Visibleto False) • Change Header text • Set alignment of Price to Right(under ItemStyle)

  6. Template Fields • Can have more control by turning field into a Template • Edit from tasksand edit databindings for that field

  7. Template Fields • Example: Binding Text format to Currency

  8. Adding Command Elements • Example: Purchase button for each book • Enable Selection • Edit columns • Move to bottom • Set type to button • Set select text to “Add to Cart” • Convert to TemplateField

  9. Adding Command Elements • Make sure each button knows ISBN of book selected • Bind ISBN to CommandArgument of the button • Passed to function when button press event occurs

  10. Handing Selection Events • Must write code for GridView_RowCommand function • Called when select occurs on row of gridview • Extract ISBN from the event object e • Coerce it to original type if necessary

  11. Editing in GridView • Can give users ability to UPDATE field values and DELETE records in database through GridView • Must connect to SQLDataSource with these abilities added • Add abilities in GridView tasks

  12. Editing in Gridview • New “Command Field” column created • Can edit position/forms/names in Edit Columns

  13. Editing in Gridview • May need to manually set queries in source • Initially ‘?’ inserted • May cause errors when DELETE or UPDATE actually run • Replace ‘?’ with @fieldname

  14. Example: ASP.NET Shopping Cart • Customer adds book • Record added to Orderstable • Contains session ID • Cart shows books selected • Query by that session ID

  15. Adding New Orders • SqlDataSource to get all books • Gridview linked to it • SqlDataSource to query for books with selected ISBN • ISBN stored in session • SqlDataSource to insert new record into Orders table

  16. Adding New Orders Extract ISBN from selected row of Gridview and store in session Extract the Session ID to use to link to customer in Order table Execute query from ISBN stored in Session and extract title and price from (single) result Execute insert to put all session information into Orders table

  17. Adding New Orders • Key idea: temporary storage of information into session fields • Can link queries/inserts to them (just like control fields) • May need to edit command to remove extra fields it finds in database (such as quantity, etc.) to match the query

  18. Displaying the Cart • Link SQLDataSource to ID stored in session • Queries Orders for all records with that session ID

  19. Displaying the Cart • Link Gridview to SqlDataSource • Add desired controls for delete, update • Add delete, update commands to SqlDataSource • Edit commands to use proper syntax

  20. Event Handling for Errors • Updating a field causes an event • Done before commit, so can validate changes to database • Use controlname_ItemUpdating for UPDATEe.NewValues(“fieldname”) gets value updated at a field • e.Cancel = True cancels change if change invalid • Example: Validate quantity change to insure > 0

More Related