i

ASP.Net A Complete Guide

Data Source Controls

Data source controls are the server-side controls. You can simply drag  & drop controls from the toolbox and put it on your page at design time. They manage the tasks of inserting, updating, selecting, and deleting data on a web page. Data source control performs those tasks in combination with data-bound controls. It has no user-interface. They implemented as server controls so that they can help to the declarative syntax. The data-bound controls provide the UI elements that enable a user to interact with the data by triggering events & that will give a call to the data source controls.

There are six data source controls available in .NET. They can found in a “System.Web.UI.WebControls” namespace.

  • XmlDataSource

  • SiteMapDataSource

  • SqlDataSource

  • AccessDataSource

  • ObjectDataSource

  • DataSetDataSource 

  • XmlDataSource

It represents an XML data. It can be used to display both hierarchical and tabular data. It typically loads data from an XML file, which specified by the DataFile property. XML data can also store directly by the data source control in string form. If we want to transform the XML data before it displayed by a data-bound control, we can provide an Extensible Stylesheet Language style sheet for the conversion. As with the XML data, we load the style sheet from a file, specified by the TransformFile property, but we can also store in string form using the Transform property.

Example:

We will see one example, which demonstrates how we can use the XmlDataSource in application

We will create a web site. We will add one form. I have added a web form, and its name is "XmlDataSource.asp"

You can see the Toolbox on the left side, which will display the "XmlDataSource" item.

We will drag that item newly added web page. Below is a screenshot I have added the new "XML file."

Now go to the design mode and click on the smart tag button the “XmlDataSource” and click on the “Configure Data Source." It will open the window like below.

Now, go to the "TreeView" Control.

I choose the data source selects the "XmlDataSourceId1" as it is the id of "XmlDataSource " that we just created in the above steps.

You can see the latest code in the file "XmlDataSource.aspx."

Design form will look like below:

 

 

Below will be the final output.