03.11.2016 Views

Beginning ASP.NET 4.5 in CSharp and VB Opsylum

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Customiz<strong>in</strong>g the Appearance of the Data Controls x 473<br />

see on-screen, be it fewer columns, different column head<strong>in</strong>gs, or different controls to display data.<br />

Fortunately, this is really easy to do with the Fields editor <strong>in</strong> VS. In the next section you see how to<br />

use this editor to create <strong>and</strong> modify the different types of built-<strong>in</strong> columns <strong>and</strong> fields. In the section<br />

that follows, you see how to customize the fields even further with user-def<strong>in</strong>ed templates.<br />

Configur<strong>in</strong>g Columns or Fields of Data-Bound Controls<br />

With<strong>in</strong> the or element of the GridView <strong>and</strong> the DetailsView, you can add the<br />

types of fields shown <strong>in</strong> the follow<strong>in</strong>g table.<br />

FIELD TYPE<br />

BoundField<br />

ButtonField<br />

CheckBoxField<br />

Comm<strong>and</strong>Field<br />

HyperL<strong>in</strong>kField<br />

ImageField<br />

TemplateField<br />

DESCRIPTION<br />

The default field for most database types. It renders as simple text <strong>in</strong> readonly<br />

mode, <strong>and</strong> as a TextBox <strong>in</strong> edit mode.<br />

Renders as a l<strong>in</strong>k or a button enabl<strong>in</strong>g you to execute a comm<strong>and</strong> on the<br />

server.<br />

Renders as a read-only check box <strong>in</strong> read-only mode, <strong>and</strong> as an editable<br />

check box <strong>in</strong> edit mode.<br />

Enables you to set up various comm<strong>and</strong>s, <strong>in</strong>clud<strong>in</strong>g edit<strong>in</strong>g, <strong>in</strong>sert<strong>in</strong>g, updat<strong>in</strong>g,<br />

<strong>and</strong> delet<strong>in</strong>g.<br />

Renders as a l<strong>in</strong>k (an element). You can set properties like<br />

DataNavigateUrlFields, DataNavigateUrlFormatStr<strong>in</strong>g, <strong>and</strong><br />

DataTextField to <strong>in</strong>fluence the behavior of the hyperl<strong>in</strong>k. You see more of<br />

this <strong>in</strong> the next exercise.<br />

Renders as an element <strong>in</strong> the browser.<br />

Enables you to def<strong>in</strong>e your own look <strong>and</strong> feel for various templates, like<br />

ItemTemplate, InsertItemTemplate, <strong>and</strong> EditItemTemplate.<br />

Clearly, each field type serves a dist<strong>in</strong>ct purpose so you can choose the one that best fits your needs.<br />

You see some of these field types <strong>in</strong> more detail <strong>in</strong> the next exercise.<br />

TRY IT OUT<br />

Customiz<strong>in</strong>g GridView Columns<br />

In this exercise, you see how to do the follow<strong>in</strong>g <strong>in</strong> the Reviews.aspx page:<br />

‰ Use the Fields editor to customize the fields for the GridView with reviews.<br />

‰ Use a HyperL<strong>in</strong>k column to create a l<strong>in</strong>k to a details page that enables you to manage the details of<br />

a review.<br />

‰ Format the output of the exist<strong>in</strong>g BoundField columns.<br />

‰ Use a custom function <strong>in</strong> the Code Beh<strong>in</strong>d to have full control over the output <strong>in</strong> a<br />

TemplateField.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!