Programming the DataList Control


You ve set your layout for the Guestbook listing, and you ve defined the data-binding expressions for the controls in the templates. You have one task left, which involves writing a tiny bit of code.

When you were creating the data-binding expressions, I said that they run after the SQL query has run. That s true, but it s not the entire story. You actually need to explicitly cause data binding to occur by calling the DataList control s DataBind method. Making that call tells the DataList control to go through the result set, bind the controls to the data, and create output based on the template.

Switch to Code view, and create the following Page_Load event handler:

Sub Page_Load(     If Not Page.IsPostBack Then         DataList1.DataBind()     End If End Sub

You only need to bind the controls to the data once, so you call the DataBind method only the first time the page runs. After the first time you bind the control, the control maintains its own viewstate.




Microsoft ASP. NET Web Matrix Starter Kit
Microsoft ASP.NET Web Matrix Starter Kit (Bpg-Other)
ISBN: 0735618569
EAN: 2147483647
Year: 2003
Pages: 169
Authors: Mike Pope

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