Presentation is loading. Please wait.

Presentation is loading. Please wait.

Using the DetailsView and FormView Controls. Slide 2 DetailsView (Introduction) Use the DetailsView control to Display a single record at a time Insert,

Similar presentations


Presentation on theme: "Using the DetailsView and FormView Controls. Slide 2 DetailsView (Introduction) Use the DetailsView control to Display a single record at a time Insert,"— Presentation transcript:

1 Using the DetailsView and FormView Controls

2 Slide 2 DetailsView (Introduction) Use the DetailsView control to Display a single record at a time Insert, edit, and delete records

3 Slide 3 DetailsView Characteristics (1) It’s really a single record version of the GridView control Paging works the same way Data binding works the same way The event model is nearly identical ItemInserting and ItemInserted appear because you can add rows ItemCreated fires each time a row is created

4 Slide 4 DetailsView Characteristics (2) Basically, the element replaces the element Styles work similarly AlternatingRowStyle, CommandRowStyle, EditRowStyle, InsertRowStyle, etc…

5 Slide 5 DetailsView (Example) Just by binding the DetailsView to a DataSource, you get basic selection and editing capabilities See DetailsViewExample1

6 Slide 6 DetailsView (Configuring 1) You can use the Smart Editor to do much of the boiler plate configuration

7 Slide 7 DetailsView (Configuring 2)

8 Slide 8 DetailsView (Fields Introduction) If the AutoGenerateFields property is true, the fields will be created automatically If not, you need to create each field manually

9 Slide 9 DetailsView (Code Example) <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowInsertButton="True" /> <asp:BoundField DataField="fldCASIndexNumber" HeaderText="CAS" ReadOnly="True“ SortExpression="fldCASIndexNumber" /> <asp:BoundField DataField="fldChemicalName" HeaderText="Chemical" SortExpression="fldChemicalName" /> <asp:BoundField DataField="fldCASRegNo" HeaderText="CAS Number" SortExpression="fldCASRegNo" /> <asp:CheckBoxField DataField="fldCarcinogenic" HeaderText="fldCarcinogenic" SortExpression="fldCarcinogenic" />

10 Slide 10 DetailsView (Fields 1) Take a look at the Field Editor (fields have different types) The following are used to create visible controls to display bound data (Set the DataField property BoundField CheckBoxField HyperLinkField ImageField ButtonField TemplateField

11 Slide 11 DetailsView (Fields 2) Use the CommandField to display automatically wired buttons ShowDeleteButton ShowInsertButton ShowEditButton Example: <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowInsertButton="True" />

12 Slide 12 DetailsView (Working with the Current Row) Each row has a data type of DetailsViewRow The RowType property contains an enumeration depicting the type of row ( DataRow, Header, Footer, etc… Example if (row.RowType == DataControlRowType.Header) { // Do something. }

13 Slide 13 DetailsView (Updating Records) Like the GridView The DataKeyNames property must define a record key The data source must be set up for updates Create CommandFields for the Insert, Update, and Delete buttons See DetailsViewExample2.aspx

14 Slide 14 DetailsView (Templated Fields) You have two choices for field layout Use what the DetailsView provides Create a Template field and define the following three templates

15 Slide 15 The FormView Control (Introduction) The control operates similar to the DetailsView However, instead of having to create custom templates for everything, there are a predefined set of templates to work with In fact, all records are based on templates The tools and designers help you create these Use Eval and Bind to bind the data

16 Slide 16 The FormView Control (Templates 1) ItemTemplate appears while a record is NOT being edited or deleted InsertItemTemplate appears while a record is being inserted EditItemTemplate appears while a record is being header EmptyDataTemplate appears when there are no records

17 Slide 17 The FormView Control (Templates 2) HeaderTemplate is the header row at the top It can contain any html or ASP controls. FooterTemplate is the footer row at the bottom The same is true here

18 Slide 18 The FormView Control (Templates 3) PagerTemplate appears in the pager row The The FormView Control (Templates 2) stores the ‘magical’ pager arguments Next, Prev, First, Last Formview.PageCount contains the number of pages Formview.PageIndex contains the number of the current page Handle PageIndexChanged when the page number changes ( CommandArgument must be set to page )

19 Slide 19 Template Contents For each template, you define the bound controls that will display the data, along with the formatting The most common practice is to use tables


Download ppt "Using the DetailsView and FormView Controls. Slide 2 DetailsView (Introduction) Use the DetailsView control to Display a single record at a time Insert,"

Similar presentations


Ads by Google