How To Create Data Connections (Databinding) In ASP.NET (Part -1)

I previous posts i discussed about how to make master pages easily using Microsoft Expression Web.By following my earlier Master page design tutorials, here is my first post on Creating database connection in ASP.NET using Microsoft Web Expression and Visual Studio 2008. This section discusses the various ways to data bind inside a data-bound control template.

Visual Studio and Expression web introduced a number of new Web controls designed for accessing and modifying data. These controls allow page developers to decoratively access and modify data without writing any code to perform the data access. you can add any type of data in Asp.net website.
In this post i tell you how to Create Data Connections (Databinding) in Asp.net using Expression Web.

What is Data Binding ?
Data binding provides a way for developers to create a read/write link between the controls on a form and the data in their web application.Data binding can also mean that if an outer representation of the data in an element changes, then the underlying data can be automatically updated to reflect the change.In Visual Studio 2008 or Expression Web, Windows Forms data binding allows you to access data from databases as well as data in other structures, such as arrays and collections.

Data binding provides a simple and consistent way for applications to present and interact with data. Elements can be bound to data from a variety of data sources in the form of Objects and XML.ItemsControls such as ListBox,ListView etc.. have built-in functionality in Visual Studio and Expression Web to enable flexible styling of single data items or collections of data items. Sort, filter, and group views can be generated.
In this tutorial i am using SQL 2000 "Northwind Database".Make sure you have already installed SQL 2000 on your System.
If you have Access database choose AcssessDataSource,If you have Xml data choose XmlDataSource.here i am using SqlDataSource.

How To Create Data Connections Asp.Net
Add Data source library to Toolbox.
Go to Task Panes Click on Data Source Library.


In data source library task pane you can see the list of connections,Here we have (0) connections,We can set more the one database in Asp.net website.
To create new connection,Click on New ASP.NET Connection.

How To Create Data Connections Asp.Net
Here you can choose what kind of data connection you are going to make,i choose Microsoft SQL Server.

How To Create Data Connections Asp.Net
Press Refresh button click your SQL Server.In connect to data base,Select the database name,Here i am connecting Northwind database.

How To Create Data Connections Asp.Net
Click on Test Connection.If Test connection Succeeded Click Ok.

How To Create Data Connections Asp.Net
Rename the Connection name if you want.

How To Create Data Connections Asp.Net
Here you can see a new connection called NorthwindConectionString1 is added to Data Source Library.

How To Create Data Connections Asp.Net
Now in Asp.net tool box,just Drag n drop SqlDataSource in Content area(ContentPalceHolder).

How To Create Data Connections Asp.Net
Now you have a option to configure your data,Click on Configure Data Source.

How To Create Data Connections Asp.Net
Choose the Data connection NorthwindConectionString1.

How To Create Data Connections Asp.Net
Here you have a option to choose tables,I am using Customers table.where i just wanted to display all the information of Customers table.

How To Create Data Connections Asp.Net
Here you can choose columns to connect,here i choose (*) all columns.Click Ok.

How To Create Data Connections Asp.Net
You can test all Customers tables query,To do so click Test Query.Click finish.

How To Create Data Connections Asp.Net
To display data on Asp.Net website we have to using one of the data control in toolbox.
Here i am using DataList.

DataList:
The DataList control is, like the Repeater control, used to display a repeated list of items that are bound to the control.DataList Web server control is a flexible data-bound container control that allows authors to customize the display of multiple rows of data, and offers built-in support for selecting and editing data in the control.
Now Drag n Drop DataList in content area where you want.

How To Create Data Connections Asp.Net
Now in DataList Tasks,Choose the Data Source,SqlDataSource.

How To Create Data Connections Asp.Net
Here you can see all of the database column names are automatically added ,exactly as appears in database,The actual content is represented by "abc".previw in browser you will see actual information.

How To Create Data Connections Asp.Net
Now save the aspx page.preview in web browser. it will look like this.

How To Create Data Connections Asp.Net You can see all customers table appears in our ASP.NET Website.
Next part i will show you in another Tutorial.

Share this

Related Posts

There was an error in this gadget