Download presentation
Presentation is loading. Please wait.
Published byHarold Simpson Modified over 9 years ago
1
Chapter 9 Customizing Data with Web Controls
2
ASP.NET 2.0, Third Edition2
3
Bound data fields/columns get the data and display it from the source Can by styled Can specify what field to use for data Template data fields/columns can contain controls, text, inline scripting to create the content of a cell Ch8_dataview.aspx uses a template control to display an image rather than text ASP.NET 2.0, Third Edition3
4
The templates in your Data control are the parts of the control that determine how to display specific data. HeaderTemplate is used to configure the data contained within the header section. Instead of using the HeaderText property for the column control, you will use HeaderTemplate to modify contents of the header cell. FooterTemplate is used to configure the data contained within the footer section. ItemTemplate is used to configure how the row will appear in display mode. The data is actually displayed in read-only mode in this template. The GridView and DetailsView controls allow you to format the rows of data using columns. EditItemTemplate allows you to configure the columns in edit mode. Therefore, the user can change the values of the data. Instead of editing the data using text boxes, you can use other types of controls such as check boxes and drop-down lists to edit the data. ASP.NET 2.0, Third Edition4
5
5
6
6
7
7
8
8
9
9
10
AlternatingItemStyle — alternating rows EditItemStyle — row being edited; the EditItemStyle is used in conjunction with the EditItemTemplate in the Data control FooterStyle — the footer row HeaderStyle — the header row ItemStyle — individual items within the list or control SelectedItemStyle — currently selected item SeparatorStyle — content that is between each item ASP.NET 2.0, Third Edition10
11
Ch9_DataList.aspx Properties: Header style Examine the markup ASP.NET 2.0, Third Edition11
12
ASP.NET 2.0, Third Edition12
13
ASP.NET 2.0, Third Edition13
14
ASP.NET 2.0, Third Edition14
15
Many of the template and style techniques can also be applied to the other controls because they inherit the same classes You can use templates to modify the Repeater control Remember that the Repeater control repeats only once for each row of data; you cannot configure the Repeater control in Design view Within the ItemTemplate object, you can retrieve the values of the data columns using, where ColumnName is the name of the column in the database You can format the output using any of the standard HTML tags ASP.NET 2.0, Third Edition15
16
Ch9_RepeaterTemplate.aspx The ItemTemplate specifies how each item is to be displayed ASP.NET 2.0, Third Edition16
17
Ch9_DataListTemplates.aspx RepeatColumns HeaderTemplate FooterTemplate ASP.NET 2.0, Third Edition17
18
The GridView control contains a collection of columns Columns can be bound to data in the record or unbound BoundFields are used to insert a button that can activate row-specific procedures You can modify the button’s text and type using the LinkButton or Button properties You can use the CommandName property to identify a procedure that is called when the button is clicked The ItemCommand event is raised when any button is clicked within a GridView control ASP.NET 2.0, Third Edition18
19
TemplateFields allows you to customize the columns in both display and edit modes HyperLinkFields displays a hyperlink that you can customize You can hard code the text displayed and the URL of the hyperlink, or set these properties with values from the data ButtonFields allows you to insert buttons that will be used to execute custom commands CommandFields contains three predefined buttons that allow you to change the mode of the row from display to edit ImageFields allows you to bind data to image controls CheckBoxFields allows you to customize the value as a check box ASP.NET 2.0, Third Edition19
20
All BoundField columns also allow you to specify the DataField property, which identifies the column from the data source bound to the column DataFormatString property identifies the formatting rules for the contents of the BoundField object You must set the ReadOnly property to true for fields where you modify the DataFormatString property ReadOnly property is used with BoundField objects to stop the user from editing a column when the GridView control is in edit mode ASP.NET 2.0, Third Edition20
21
All columns within the GridView control allow you to configure the appearance of the column: HeaderText HeaderImageURL FooterText properties Visible property allows you to show or hide the column SortExpression property is used to identify the column from the data source that is used when sorting the column ASP.NET 2.0, Third Edition21
22
When you update a BoundField column, the contents of the columns are sent using GridViewCommandEventArgs ; the arguments in the column are represented with the variable e When you want to access a specific cell within a column, you must use the Item property of the e object The e.Item property contains an indexed Cells collection that contains one Cell object for each column in the GridView control The columns in the GridView are numbered starting with 0 So, e.Item.Cells(0) would represent the first column in the GridView control ASP.NET 2.0, Third Edition22
23
In a master-detail page, you configure the master control to pass the value to the detail control Often the master control is the GridView control and the detail control is the DetailsView control In this section, you will learn to create and bind a drop-down list to a field Then when the user selects a value, another list is generated Finally, the user selects a record from a GridView control, and the specific record data is displayed in a DetailsView control ASP.NET 2.0, Third Edition23
24
Ch8_GridViewTemplate.aspx The second field is a template field The template field in the GridView control Item template uses an inline expression to create a hyperlink The footer template uses an inline expression to count the number of items displayed ASP.NET 2.0, Third Edition24
25
Put numeric data into the cells rather than strings Remove the auto-generated columns Add bound columns corresponding to the data columns Format the columns ASP.NET 2.0, Third Edition25
26
Ch9_MasterDetails.aspx Selections in controls at the top provide the information to filter controls farther down ASP.NET 2.0, Third Edition26
27
Visual Studio allows the user to create item templates and project templates Visual Studio stores user-defined templates separate from the application templates User templates are templates that are only available to the individual user When Visual Studio was installed, a folder was created for the user; this folder contains user-specific files such as the user templates ASP.NET 2.0, Third Edition27
28
ASP.NET 2.0, Third Edition28
29
ASP.NET 2.0, Third Edition29
30
The DataList, Repeater, and GridView controls use an ItemTemplate to display the values. The DataList and DataGrid controls use templates to create the header, footer, and item sections of the Data control. You can format these controls using the graphical Style Builder tool or manually. The Repeater control must be edited manually in HTML view. There is no graphical tool to edit the Repeater control. Styles are used to format the appearance of the control. You can format the control using style sheets or formatting properties within the control. Templates are used to display the content within the control. There is header, footer, item, alternating item, and other specialized templates for each of the Data controls. You can modify the templates manually or using the graphical user interface within the web editor. ASP.NET 2.0, Third Edition30
31
The GridView control allows you to create a collection of bound and unbound columns. Bound columns contain a value that is bound to a value in the database. Bound columns are referred to as BoundFields. Other types of columns include HyperLinkFields and TemplateFields. TemplateFields allow you the most flexibility. Even though the column is not bound, you can still retrieve and display the data in the column. Master-detail pages provide a way to retrieve data that is based on a selection that the user makes in another Data control. The DataSource control uses this data to create a parameter query and binds the new data set to the Data control. Other types of data, such as a QueryString or session parameter, can also be used as a parameter for the DataSource control. Another tool to improve your efficiency with web programming is custom templates. ASP.NET 2.0, Third Edition31
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.