[Translation] Use XML to bind data for list controls

xiaoxiao2021-03-06  14

Original article: http://www.codeproject.com/aspnet/xmlboundlistControl.asp

Use XML to bind data for list controls

Author: Enrico Elizar Samuel understand the use of various XML data binding for the list control in different ways.

Introduction

In the web development project, we need to write some code to read dynamic data from the data source to the list control. In the classic ASP period, this is a relatively difficult task. For example, we must query the database to find the Recordset and reread Recordset when manually created an HTML tag.

Now in ASP.NET, you have a better way to do the same thing. In addition, in addition to the database as a data source, you can also use a variety of data sources, such as an XML file. Which one is better? This will argue in performance, adaptability, reliability, confinement, security, etc. Here, I don't want to discuss this.

This article discusses several optional methods to bind different types of data sources (mainly XML files). Although we use Listbox as an example, you can easily extend this technique to other list controls from the System.Web.ui.WebControls.ListControl class. They include CheckBoxList, DropDownList, and RadiobuttonList.

Hard coded list box

As a beginning, let's recall how we use HTML to define a list box (listbox). The original code of a list box is shown below. This is the easiest way, and the cost is the least, but it lacks some flexibility to control the behavior of the list box.