CH 14 HOW TO USE THE GRIDVIEW CONTROL

  • Slides: 19
Download presentation
CH 14 HOW TO USE THE GRIDVIEW CONTROL [452 - 467] AKASH KURVA SHEKARAPPA

CH 14 HOW TO USE THE GRIDVIEW CONTROL [452 - 467] AKASH KURVA SHEKARAPPA PRESENTATION ID: 6 CSCI 5633 -1

OUTLINE • How to customize paging • List application that used a Grid. View

OUTLINE • How to customize paging • List application that used a Grid. View Control • How to update Grid. View data • How to work with command fields • How to use events raised by the Grid. View control • How to insert a row in a Grid. View control • A maintenance application that uses a Grid. View Control

HOW TO CUSTOMIZE PAGING Ø First, get the new page index with New. Page.

HOW TO CUSTOMIZE PAGING Ø First, get the new page index with New. Page. Index property and set it to the Grid. View Page. Index property. Ø And, then fetches the records on the basis of Page. Size and the current Page. Index values from the database for that specific page number. Ø Now, if you have 50 records in the database and your Page. Size is 10, then the Grid. View is bound with only 10 records to corresponding Page. Index.

Attributes of the Grid. View control that affect paging: Attribute Description Allow. Paging Set

Attributes of the Grid. View control that affect paging: Attribute Description Allow. Paging Set to True to enable paging. Page. Size Specifies the number of rows to display on each page. The default is 10. Ø This attribute tells the Grid. View that we are going to use Custom. Paging with the control and helps us to implement built in paging with custom paging logic. Ø This attribute takes the Boolean value either true or false. You must set the value true to implement the built-in custom paging with Grid. View. Ø You can use the Page. Size attribute of the Grid. View element to specify the number of rows to display on each page.

ATTRIBUTES OF THE PAGERSETTINGS ELEMENT Attribute Description Mode Controls what buttons are displayed in

ATTRIBUTES OF THE PAGERSETTINGS ELEMENT Attribute Description Mode Controls what buttons are displayed in the pager area. You can specify Next. Previous, Next. Previous. First. Last, Numeric, or Numeric. First. Last. First. Page. Text The text to display for the first page button. The default is < , which displays as << First. Page. Image. Url The URL of an image file used to display the first page button Previous. Page. Text The text to display for the previous page button. The default is < , which displays as < Previous. Page. Image. Url The URL of an image file used to display the previous page button Next. Page. Text The text to display for the next page button. The default is > , which displays as > Next. Page. Image. Url The URL of an image file used to display the next page button Last. Page. Text The text to display for the last page button. The

You can also add Pager. Settings element to control the appearance of the pager

You can also add Pager. Settings element to control the appearance of the pager area. Ø You can also add a Pager. Settings element to control the appearance of the pager area.

A LIST APPLICATION THAT USES A GRIDVIEW CONTROL:

A LIST APPLICATION THAT USES A GRIDVIEW CONTROL:

HOW TO UPDATE GRIDVIEW DATA Ø To edit or delete any fraud or duplicate

HOW TO UPDATE GRIDVIEW DATA Ø To edit or delete any fraud or duplicate or damaged data from the table there is a method in Grid. View to edit, delete and update. Ø We can Update and Delete statements in the Grid. View. Ø To edit data we need to click the edit button to edit a row. Ø If we click delete button, Grid. View control calls the data source control’s Delete method. Ø When we click Edit button, Grid. View control places the particular row in edit mode.

HOW TO WORK WITH COMMAND FIELDS: Ø A command field is a Grid. View

HOW TO WORK WITH COMMAND FIELDS: Ø A command field is a Grid. View column that contains one or more command buttons. Ø Typical code to define command fields

THE FIELDS DIALOG BOX FOR WORKING WITH COMMAND FIELD:

THE FIELDS DIALOG BOX FOR WORKING WITH COMMAND FIELD:

ATTRIBUTES OF THE COMMAND FIELD ELEMENT: Attribute Description Button. Type Specifies the type of

ATTRIBUTES OF THE COMMAND FIELD ELEMENT: Attribute Description Button. Type Specifies the type of button displayed in the command field. Causes. Validation Specifies whether the validation should be performed if the user clicks the buttons. Validation. Group Specifies the name of the Group to be validated if Causes. Validation is True.

ATTRIBUTES THAT SHOW BUTTONS AND SET THE TEXT/IMAGES THEY DISPLAY: Button Show Text Image

ATTRIBUTES THAT SHOW BUTTONS AND SET THE TEXT/IMAGES THEY DISPLAY: Button Show Text Image Cancel Show. Cancel. Button Cancel. Text Cancel. Image Delete Show. Delete. Button Delete. Text Delete. Image Edit Show. Edit. Button Edit. Text Edit. Image Select Show. Select. Button Select. Text Select. Image Update n/a Update. Text Update. Image Ø A command field adds buttons that let the user to edit, delete, or select data. Ø The Command. Field element also provides for an Insert button, but the Grid. View control doesn’t directly support insert operations.

HOW TO USE EVENTS RAISED BY THE GRIDVIEW CONTROL • When the user clicks

HOW TO USE EVENTS RAISED BY THE GRIDVIEW CONTROL • When the user clicks the Delete button in a Grid. View row, two events are raised. The Row. Deleting event is raised before the row is deleted, and the Row. Deleted event is raised after the row has been deleted. • The most common reason to handle the before-action events is to provide data validation. • The after-action events give you an opportunity to make sure the database operation completed successfully.

EVENTS RAISED BY THE GRIDVIEW CONTROL Event Raised when… Row. Canceling. Edit The Cancel

EVENTS RAISED BY THE GRIDVIEW CONTROL Event Raised when… Row. Canceling. Edit The Cancel button of a row in edit mode is clicked Row. Data. Bound Data binding completes for a row Row. Deleted A row has been deleted Row. Deleting A row is about to be deleted Row. Editing A row is about to be edited Row. Updated A row has been updated Row. Updating A row is about to be updated Selected. Index. Changed A row has been selected Selected. Index. Changing A row is about to be selected

HOW TO INSERT A ROW IN A GRIDVIEW CONTROL Ø First we need to

HOW TO INSERT A ROW IN A GRIDVIEW CONTROL Ø First we need to create a set of input controls such as text boxes. Ø Next you must provide a button that the user can click to start the insertion. Ø Then in event handler for this button you can set the insert parameter values to the values entered by the user and call the data source Insert Method.

METHOD AND PROPERTIES OF THE SQLDATASOURCE CLASS FOR INSERTING ROWS Method Description Insert() Executed

METHOD AND PROPERTIES OF THE SQLDATASOURCE CLASS FOR INSERTING ROWS Method Description Insert() Executed the Insert command defined for the data source Property Description Insert. Command The Insert command to be executed Insert. Parameters[“names”] The parameter with the specified name Ø The Grid. View control doesn’t support insert operations, but you can use the Grid. Views data source to insert rows into the database. When you do, the new row will automatically be shown in the Grid. View control.

A MAINTENANCE APPLICATION THAT USES A GRIDVIEW CONTROL Ø The category Maintenance application uses

A MAINTENANCE APPLICATION THAT USES A GRIDVIEW CONTROL Ø The category Maintenance application uses a Grid. View control to let the user update or delete rows in the categories table.

REFERENCE: Ø “Murach's ASP. NET 4 Web Programming with C# 2010 4 th Edition",

REFERENCE: Ø “Murach's ASP. NET 4 Web Programming with C# 2010 4 th Edition", Anne Boehm and Joel Murach, April 26, 2011. (ISBN 978 -1890774615)

THANK YOU

THANK YOU