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.

534 x CHAPTER 14 LINQ AND THE ADO.<strong>NET</strong> ENTITY FRAMEWORK<br />

When the ListView control needs to display its data, it creates an item based on the <br />

for each data item <strong>in</strong> the data source. In this example, each data item is a strongly typed Picture<br />

object, which provides access to properties such as ToolTip <strong>and</strong> Description:<br />

<br />

<br />

...<br />

ToolTip:<br />

<br />

...<br />

<br />

<br />

<br />

With this code <strong>in</strong> place, each item <strong>in</strong> the data source is presented as a series of labels that display relevant<br />

properties of the picture. Eval(PropertyName) is used to retrieve the requested value from the<br />

object, which is then displayed as the Label control’s text. Note that at this stage, the <br />

only displays data about the picture. You see how to upload <strong>and</strong> display real pictures later.<br />

Note the Comm<strong>and</strong>Name of the Button control <strong>in</strong> the ItemTemplate. It’s set to Delete, which turns this button<br />

<strong>in</strong>to a true Delete button. When you click it, the ListView figures out what picture you clicked the button<br />

for <strong>and</strong> then <strong>in</strong>structs the EntityDataSource control to delete the associated picture from the database.<br />

The code you added to the theme’s CSS files displays the items <strong>in</strong> an organized way. By sett<strong>in</strong>g the<br />

class attribute of the control to ItemConta<strong>in</strong>er, the follow<strong>in</strong>g CSS is applied to that list:<br />

.ItemConta<strong>in</strong>er<br />

{<br />

width: 600px;<br />

list-style-type: none;<br />

clear: both;<br />

}<br />

The first property sets the entire width of the list to 600 pixels <strong>and</strong> the second declaration removes the<br />

bullet from the items <strong>in</strong> the list. Each item <strong>in</strong> the list is then displayed with<strong>in</strong> a element, to which<br />

the follow<strong>in</strong>g CSS is applied:<br />

.ItemConta<strong>in</strong>er li<br />

{<br />

height: 300px;<br />

width: 200px;<br />

float: left;<br />

}<br />

Each item gets a forced width of 200 pixels. The float property tells the elements to float next<br />

to each other. With<strong>in</strong> the parent area of 600 pixels you can fit three elements of 200 pixels each,<br />

caus<strong>in</strong>g the fourth <strong>and</strong> further elements to be placed on their own l<strong>in</strong>e. This is a great alternative to present<strong>in</strong>g<br />

data with HTML tables, which generally needs a lot more markup to achieve the same effect.<br />

F<strong>in</strong>ally, each image with<strong>in</strong> the element gets a forced width of 180 pixels <strong>and</strong> 10 pixels of marg<strong>in</strong> at the<br />

top <strong>and</strong> bottom, 20 pixels on the right (to create some room between the images), <strong>and</strong> none at the left side:<br />

.ItemConta<strong>in</strong>er li img<br />

{

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

Saved successfully!

Ooh no, something went wrong!