What Are List Controls?

   

Now back to displaying data in ASP.NET. I can sum it up like this: It's fun for the whole family. Well, at least it's fun for you and anyone else working in ASP.NET.

In the past, with traditional interpreted scripting languages, displaying data was one of the big creators of spaghetti code's abundance. To display data you could either jump in and out of HTML code or you could write HTML code using ASP's Response object's Write() method.

Below is an example of a page written with traditional ASP. The <select box> in this page is created by having its option tags written by the Response object. The table that follows uses a example of spaghetti code where what is called "context switching" occurs. Context switching is just a fancy word for switching back and forth between HTML and ASP.

Traditional ASP trad_spaghetti.asp
<%  dim arrSelectBox(3)  arrSelectBox(0)="Cake"  arrSelectBox(1)="Cookies"  arrSelectBox(2)="Ice Cream"  arrSelectBox(3)="Pie"  %>  <html>  <head>  <title>Traditional Example</title>  </head>  <body bgcolor="#FFFFFF" text="#000000">  This is a select box created by writing HTML through the Response.Write method.  <br>  <Select name="select">  <%  i=0  for i=0 to Ubound(arrSelectBox)      Response.Write "<option value=""" & arrSelectBox(i) & """>"      Response.Write arrSelectBox(i)      Response.Write "</option>"  next  %>  </Select>  <br><br>  This is building a table with more spagetti code<br>  <table border="1">  <%for i=0 to Ubound(arrSelectBox)%>  <tr><td><%=arrSelectBox(i)%></td></tr>  <%next%>  </table>  </body>  </html> 

Now that you've gone through many examples of the advantages of objects and server controls, you can see that this method of displaying lists of data is a bit antiquated. ASP.NET has to have a better answer for this, right?

Let me assure you that ASP.NET has a much, much, much better answer than this for displaying lists and tables of data. These server controls let you do just about anything you want with this type of data, including formatting, displaying, listing, paging through large amounts of data, and even editing data without much effort at all.

The server controls can pretty much be broken down into two categories. These aren't official categories, but I think it makes it easier to group them into these three categories:

  • Simple List Controls. CheckBoxList, DropDownList, ListBox, RadioButtonList

  • Repeater Control. Repeater

  • Complex List Controls. DataList, DataGrid

The controls provide you with just about every possible control you could need to display listed and tabular data, with the DataGrid in particular being able to just about butter your toast in the morning.


   
Top


ASP. NET for Web Designers
ASP.NET for Web Designers
ISBN: 073571262X
EAN: 2147483647
Year: 2005
Pages: 94
Authors: Peter Ladka

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net