ASP.NET
  Home arrow ASP.NET arrow DataList Control
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

DataList Control
By: Justin Cook
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 16
    2004-07-20

    Table of Contents:
  • DataList Control
  • Bring on the DataList
  • Selecting/Editing Templates in a DataList
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    DataList Control


    (Page 1 of 4 )

    You've traveled the long and arduous journey of reading through my 3 other articles on using the DataGrid and Repeater controls in ASP.Net. This is the last but not least, the DataList. You can look at it as either a stripped-down DataGrid or a beefed-up repeater, but either way it's got a good mix of flexibility and functionality that will make it the best choice in many situations.


    Previous articles on this topic include DataGrid and Repeater controls.


    Introduction

    In my last article, I detailed how to make good use of the Repeater control. By setting up a template for the repeating data, you saw how easy it was to surface data from a dataset onto a web page. Beyond just merely repeating or displaying the data, I illustrated a real-life application of its use, putting it to work in an e-commerce environment. To do this I explain what is meant by 'event bubbling' and how to use it effectively.

    You'll find it an easy transition to now move into the DataList control. Its use is very similar to the repeater, but it has some additional flexibility and functionality. You have more control over the display of the data, as well as provisions for data selection and editing.

    Let's get right into the code, and I'll explain how it works along the way

    Into the Code

    Like any data-bound control in .Net, we'll start off the example by retreiving the actual data with which to populate the DataList. We don't really need to re-invent the wheel here; we can use very similar code to what is used with a repeater. We'll call the binding subroutine doBinding():

    Sub doBinding()

    Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0; " & _

    "Ole DB Services=-4; " & _

    "Data Source=C:\Inetpub\wwwroot\test.mdb"

    Dim dbConnection As OleDbConnection = New OleDbConnection(strConn)

    Dim strSQL As String = "SELECT * FROM products"

    Dim dataAdapter As OleDbDataAdapter = New OleDbDataAdapter( strSQL, strConn)

    Dim dataSet As DataSet = New DataSet

    dataAdapter.Fill(dataSet)

    dList.DataSource = dataSet

    dList.DataBind()

    End Sub

    Nothing too groundbreaking here. We just made the connection, established the query string with results in a dataset filled with the products data. Then we instantiate the datalist and bind the data to it.

    Now of course this will all do exactly nothing unless we call the subroutine at some event. And naturally we will use the page load event to call it:

    sub page_load( source as Object, e as EventArgs )

    if not isPostBack then

    doBinding()

    end if

    end sub

    More ASP.NET Articles
    More By Justin Cook


       · so far so good, but the major challenge with using datalist controls is having to...
     

    ASP.NET ARTICLES

    - Disadvantages of the ASP.NET MVC Framework
    - Advantages of the ASP.NET MVC Approach
    - ASP.NET Web Forms Weaknesses
    - ASP.NET Web Forms Meets ASP.NET MVC
    - Source Code for Saving and Retrieving Data w...
    - Using GridView to Save and Retrieve Data wit...
    - Handling Dynamic Images in ASP.NET 3.5 AJAX ...
    - Retrieving Data with AJAX and the GridView C...
    - Playing with Images in ASP.NET 3.5 AJAX Appl...
    - Saving and Retrieving Data with AJAX
    - Enhancing PHP Via the ASP.NET AJAX Framework...
    - Enhancing PHP Programming with the ASP.NET A...
    - Classes and ASP.NET AJAX
    - Using ASP.NET AJAX
    - Building a Simple Storefront with LINQ





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT