Data Binding is binding controls to data from databases.With data binding we can bind a control to a particular column in a table from the database or we can bind the whole table to the data grid. Data binding provides simple, convenient, and powerful way to create a read/write link between the controls on a form and the data in their application. Working with Data Binding in ASP.NET is slightly different to working with it in VB .NET. Generally, Datasets don’t maintain a current record that is displayed in bound controls. In VB .NET, the BindingContext object handles that and it lets us set the record bound control display. In ASP.NET, there is no BindingContext object to handle that. In ASP.NET, we use a DataView to let the user select which record should be displayed in bound controls. We bind the controls using data view and use the RowFilter property of the data view to select the record we want the bound control to display. Simply said, in VB .NET we use the Dataset to bind records to the bound control and in ASP.NET we use a DataView.
Let’s understand data binding in ASP.NET with a sample. To start, create a database in Access, name it as Books.mdb. Create a table, Table1 with three columns, BookName, Publisher and ISBN. Enter some values in Table1, save and close it. On a new Web Forms page add three TextBoxes and four Buttons. The user interface should look like the image below.
From the Data tab of the toolbox (as shown in the image below) drag a OledbDataAdapter object and configure it to Table1 of theBooks database. Click here to read how to configure a Data Adapter. Once you are finished configuring the data adapter, generate the dataset by selecting Data->Generate DataSet from the main menu.
Since we will use a DataView instead of a Dataset to navigate through the record, drag a DataView object on to the Web Forms page and set the Table property of the data view to Dataset11.Table1.
Select TextBox1, click on the ellipse button for it’s DataBindings property to open the DataBinding’s dialog box. The data binding’s dialog looks like the image below.
In the Data Binding’s dialog we need to bind TextBox1 to the BookName field, TextBox2 to Publisher field and TextBox3 to the ISBN field using the DataView (DataView1). You should not use DataSet as you would in a Windows Application. Open the Code designer window and paste the following code for each button.
|Private Sub Page_Load(ByVal sender As System.Object, ByVal e As_
System.EventArgs) Handles MyBase.Load
‘filling the dataadapter and displaying the first record from the table when the
Private Sub First_Click(ByVal sender As System.Object, ByVal e As_
Private Sub Previous_Click(ByVal sender As System.Object, ByVal e As_
Private Sub Next_Click(ByVal sender As System.Object, ByVal e As_
Private Sub Last_Click(ByVal sender As System.Object, ByVal e As_
Once you are finished with the code, run the page. The first record from the table is displayed when the page loads. You can click the button to navigate through the records.
Reference : Dilip Kumar Jena ( https://mstechexplore.wordpress.com )