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.

Data Controls x 455<br />

to have unwanted HTML mixed with your own. You def<strong>in</strong>e the entire client markup through the<br />

numerous templates the control exposes. However, this flexibility comes at a price: the control has<br />

no built-<strong>in</strong> capabilities to page, sort, or modify data. You see more of the Repeater control <strong>in</strong> the<br />

next chapter.<br />

The ListView was <strong>in</strong>troduced <strong>in</strong> <strong>ASP</strong>.<strong>NET</strong> 3.5 <strong>and</strong> is a best-of-all-worlds comb<strong>in</strong>ation of the<br />

GridView, the DataList, <strong>and</strong> the Repeater. It has undergone some changes <strong>in</strong> <strong>ASP</strong>.<strong>NET</strong> 4 <strong>and</strong> <strong>4.5</strong><br />

that make it even easier to work with. The control supports edit<strong>in</strong>g, delet<strong>in</strong>g, <strong>and</strong> pag<strong>in</strong>g of data,<br />

similar to the GridView. It supports multi-column <strong>and</strong> multi-row layouts like the DataList offers,<br />

<strong>and</strong> it enables you to completely control the markup generated by the control, just as the Repeater<br />

does. It also supports <strong>in</strong>sert<strong>in</strong>g <strong>and</strong> updat<strong>in</strong>g data like the DetailsView or FormView controls. In<br />

the next chapter, you see a lot more of the ListView control.<br />

In <strong>ASP</strong>.<strong>NET</strong> 4, list controls were extended with a ClientIDRowSuffix property that enables you to<br />

<strong>in</strong>dicate the column whose value is used to create unique client-side IDs based on data <strong>in</strong> the database.<br />

For this to work, you need to set the ClientIDMode property that you saw <strong>in</strong> earlier chapters<br />

to Predictable.<br />

In <strong>ASP</strong>.<strong>NET</strong> <strong>4.5</strong>, the controls have been extended aga<strong>in</strong> with a new property: ItemType. You see<br />

this property at work <strong>in</strong> the next chapter.<br />

S<strong>in</strong>gle Item Controls<br />

The DetailsView <strong>and</strong> FormView controls are<br />

somewhat similar <strong>in</strong> that both of them can display<br />

a s<strong>in</strong>gle record at a time. The DetailsView<br />

uses a built-<strong>in</strong> tabular format to display the data,<br />

whereas the FormView uses templates to let you<br />

def<strong>in</strong>e the look <strong>and</strong> feel of your data. A simple,<br />

template-based DetailsView could look like the<br />

one shown <strong>in</strong> Figure 13-3.<br />

The FormView control <strong>and</strong> a few of the Log<strong>in</strong> controls you’ll see <strong>in</strong> Chapter 16 have a<br />

RenderOuterTable property. When you set this property to False (it defaults to True so you need<br />

to set it explicitly) the control doesn’t generate a wrapp<strong>in</strong>g HTML element. This <strong>in</strong> turn<br />

results <strong>in</strong> less code <strong>and</strong> cleaner HTML. Both controls enable you to def<strong>in</strong>e the templates for different<br />

situations, such as a read-only display of data, <strong>and</strong> <strong>in</strong>sert<strong>in</strong>g <strong>and</strong> updat<strong>in</strong>g of data. You see how to<br />

customize these templates <strong>in</strong> the second half of this chapter.<br />

Pag<strong>in</strong>g Controls<br />

FIGURE 13-3<br />

Another useful control is the DataPager, which enables pag<strong>in</strong>g on other controls. For the time<br />

be<strong>in</strong>g, you can only use it to extend the ListView control, but that might change with future versions<br />

of the .<strong>NET</strong> Framework. The ListView <strong>and</strong> DataPager controls are discussed <strong>in</strong> Chapter 14.<br />

For the data-bound controls to display someth<strong>in</strong>g useful, you need to assign them a data source.<br />

To b<strong>in</strong>d this data source to the controls, two ma<strong>in</strong> methods are available: You can assign data to<br />

the control’s DataSource property, or you can use one of the separate data source controls. In later<br />

chapters, you see how to use the DataSource property; the different data source controls are the<br />

topic of the follow<strong>in</strong>g section.

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

Saved successfully!

Ooh no, something went wrong!