VisualBuilder
  Home > Aspnet > Tutorials > Data Binding and Data Synchronization - ASP.NET Database Tutorial
Tell a friend
Link to us
Total Members
      Members: 84657
     
Sitemap Forum Chat
Home
ASP.NET Database Tutorial Home
1 . Introduction to Asp.Net 2.0
2 . Introduction to ADO.Net
3 . Connecting Access Database with AccessDataSource and GridView Control
4 . Accessing SQL SERVER Database [Using SqlDataSource]
5 . Storing Connection String in Web.Config File
6 . Inserting Records in Database
7 . Updating Records in Database
8 . Updating Records in Database
9 . Deleting Records from Database
10 . Execute Scalar: Getting Single Value from the Database
11 . Execute Reader: Fetching Records from Database
12 . Data Adapter
13 . Data Adapter and Database Connection
14 . Performing Batch Updates: Using SqlCommandBuilder
15 . Improving Performance using Stored Procedure
16 . Filtering and Sorting Data Using DataView/DataTable
17 . Data Binding and Data Synchronization
18 . SQL Transaction and Locking
19 . SQL Joins and .Net
20 . Automatically Generation of SQL Statement
 
Aspnet Group Home
Aspnet Discussion (10)
Aspnet Members (2382)
Aspnet Resources
Aspnet Source Code (388)
Aspnet Articles (1)
Aspnet Blogs
Aspnet Jobs
Aspnet Components (201)
Aspnet Books
Aspnet Websites (21)
Aspnet News (105)
Aspnet Q & A (114)
- Aspnet Ask Question
- Aspnet Questions
- Aspnet Unanswered Questions
 
GROUPS
.NET
ASP.NET
.NET
C#
ASP
Visual Basic
Java
Java
JSP
EJB
Other
Delphi
C++
Ajax
UML
JavaScript
PHP
Web Design
Web Hosting
SQL Server
Oracle
Project Management
More Groups

 
LEARNING CENTER
TUTORIALS
.NET
.NET Tutorial
ASP Tutorial
ASP.NET Database Tutorial
ASP.NET Development Tips
ASP.Net Security,Internationalisation And Deployment
ASP.NET Server Controls Tips
ASP.NET Tutorial
C Sharp Tutorial
Web Development
Flex Tutorial
HTML Tutorial
Learn AJAX Tutorial
PHP Tutorial
Software Development
Database Tutorial
SQL Tutorial
UML Tutorial
Java
Ant Tutorial
EJB 3 Tutorial
Hibernate Tutorial
Java Tutorial
Java Web Component Tutorial
Java XML Tutorial
JDBC Tutorial
JDK1.5 Tutorial
JSF Tutorial
JSP And J2EE Design Tutorial
JSP Tutorial
Spring Tutorial
Struts Tutorial

RESOURCES
Q & A (434 )
Source Code (3275 )
Articles (11 )
Components (1595 )
News (888 )
Websites (1207 )

SUBMISSIONS
Submit Article
Submit Website
Submit News
Submit Source Code
Submit Component

COMMUNITY
Members Directory
Discussion Forum
Chat

SITE
About Us
Sitemap
Search
Contact Us
Link To Us
Feedback
Tell a Friend
Partners
Advertise

Aspnet database Tutorial
 Data Binding and Data Synchronization
  << Prev: Filtering and Sorting Data Using DataView/DataTable Next: SQL Transaction and Locking >>

Data binding provides a way for developers to create a read/write link between the controls on a form and the data in the application. Data binding is used within applications to take advantage of data stored in databases. DataTable object is the representation of a table, with rows and columns, in ADO.NET. DataTable contains two collections: DataColumn , representing the columns of data in a given table (which ultimately determine the kinds of data that can be entered into that table), and DataRow , representing the rows of data in a given table


 


DataView provides a layer of indirection between the actual data and its display format, thereby enabling the programmer to apply sorts and filter rows without modifying the underlying information—that is, to have different “views” on the same data. The DataViewManager on the other hand represents a view on the entire DataSet. One of the most useful aspects of the DataView is the ability to create multiple DataView objects to provide different representations of the same data. The following simple example with three separate Grid View controls illustrates the same. Each DataView applies a different SQL filter expression using the RowFilter property and each of them contains only a subset of the full data in the DataTable. If a row is modified in one view, the changes appear automatically in all other views because, there is only one data source—the linked DataTable


 


Example: Demonstrate Multiple View


 


 


DataSynchronization.aspx


 


<% @ Page Language ="C#" AutoEventWireup ="true" CodeFile ="DataSynchronization.aspx.cs" Inherits ="DataSynchronization" %>


 


<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


 


<html xmlns ="http://www.w3.org/1999/xhtml" >


<head runat ="server">


</head >


<body >


<form id ="form1" runat ="server">


<div>


<strong> Displaying Multiple Views


</strong>


<br/>


< br />


<asp:GridView ID ="grdvStore" runat ="server" AutoGenerateColumns ="False" CellPadding ="4" ForeColor ="#333333" GridLines ="None">


< FooterStyle BackColor ="#1C5E55" Font-Bold ="True" ForeColor ="White" />


<Columns>


<asp:BoundField DataField ="stor_id" HeaderText ="Store ID" />


<asp:BoundField DataField ="stor_address" HeaderText ="Address" />


<asp:BoundField DataField ="city" HeaderText ="City" />


<asp:BoundField DataField ="state" HeaderText ="State" />


</Columns>


<RowStyle BackColor ="#E3EAEB" />


<EditRowStyle BackColor ="#7C6F57" />


<SelectedRowStyle BackColor ="#C5BBAF" Font-Bold ="True" ForeColor ="#333333" />


<PagerStyle BackColor ="#666666" ForeColor ="White" HorizontalAlign ="Center" />


<HeaderStyle BackColor ="#1C5E55" Font-Bold ="True" ForeColor ="White" />


<AlternatingRowStyle BackColor ="White" />


</asp:GridView>


< br />


<asp:Button ID ="Button1" runat ="server" OnClick ="Button1_Click" Text ="Displaying Multiple Views" />


< br />


< br />


<asp:GridView ID ="grdvSecond" runat ="server" AutoGenerateColumns ="False" BackColor ="LightGoldenrodYellow" BorderColor ="Tan" BorderWidth ="1px" CellPadding ="2" ForeColor ="Black" GridLines ="None">


<FooterStyle BackColor ="Tan" />


<Columns>


<asp:BoundField DataField ="stor_id" HeaderText ="Store ID" />


<asp : BoundField DataField ="stor_address" HeaderText ="Address" />


<asp : BoundField DataField ="city" HeaderText ="City" />


<asp : BoundField DataField ="state" HeaderText ="State" />


</Columns>


<SelectedRowStyle BackColor ="DarkSlateBlue" ForeColor ="GhostWhite" />


<PagerStyle BackColor ="PaleGoldenrod" ForeColor ="DarkSlateBlue" HorizontalAlign ="Center" />


<HeaderStyle BackColor ="Tan" Font-Bold ="True" />


<AlternatingRowStyle BackColor ="PaleGoldenrod" />


</asp:GridView>


<br/>


<asp:GridView ID ="grdvThird" runat ="server" AutoGenerateColumns ="False" BackColor ="LightGoldenrodYellow" BorderColor ="Tan" BorderWidth ="1px" CellPadding ="2" ForeColor ="Black" GridLines ="None">


<FooterStyle BackColor ="Tan" />


<Columns>


<asp:BoundField DataField ="stor_id" HeaderText ="Store ID" />


<asp:BoundField DataField ="stor_address" HeaderText ="Address" />


<asp:BoundField DataField ="City" HeaderText ="City" />


<asp:BoundField DataField ="state" HeaderText ="State" />


</Columns>


<SelectedRowStyle BackColor ="DarkSlateBlue" ForeColor ="GhostWhite" />


<PagerStyle BackColor ="PaleGoldenrod" ForeColor ="DarkSlateBlue" HorizontalAlign ="Center" />


<HeaderStyle BackColor ="Tan" Font-Bold ="True" />


<AlternatingRowStyle BackColor ="PaleGoldenrod" />


</asp:GridView>


&nbsp; &nbsp;&nbsp; &nbsp; </div>


</form>


</body>


</html>


 


 


 


DataSynchronization.aspx.cs


 


using System;


using System.Data;


using System.Configuration;


using System.Collections;


using System.Web;


using System.Web.Security;


using System.Web.UI;


using System.Web.UI.WebControls;


using System.Web.UI.WebControls.WebParts;


using System.Web.UI.HtmlControls;


using System.Data.SqlClient;


 


public partial class DataSynchronization : System.Web.UI. Page


{


  protected void Page_Load( object sender, EventArgs e)


    { // GridView


    string strConn = "Data Source=localhost;Initial Catalog= pubs; user Id=sa;Password = test " ;


    string sqlQuery = "select * from stores" ;


    SqlConnection conn = new SqlConnection (strConn);


    SqlDataAdapter ada = new SqlDataAdapter (sqlQuery, conn);


    DataSet dstStore = new DataSet ();


    ada.Fill(dstStore, "Stores" );


    //Bind GridView


    grdvStore.DataSource = dstStore.Tables[ "Stores" ];


    // grdvStore.DataSource = dstStore.DefaultViewManager;


    grdvStore.DataBind();


    }


  protected void Button1_Click( object sender, EventArgs e)


    { //Displaying Multiple Views


    string strConn = "Data Source=localhost;Initial Catalog=pubs;user Id=sa;Password= test" ;


    string sqlQuery = "select * from stores" ;


    SqlConnection conn = new SqlConnection (strConn);


    SqlDataAdapter ada = new SqlDataAdapter (sqlQuery, conn);


    DataSet dstStore = new DataSet ();


    ada.Fill(dstStore, "Stores" );


    //Multiple DataView Object


    DataView dvFirst = new DataView (dstStore.Tables[ "Stores" ]);


    DataView dvSecond = new DataView (dstStore.Tables[ "Stores" ]);


    //Filter Views


    dvFirst.RowFilter = "state = 'CA'" ;


    dvSecond.RowFilter = "state = 'WA'" ;


    //Bind GridView : Only 'CA' state


    grdvSecond.DataSource = dvFirst;


    grdvSecond.DataBind();


    //Bind GridView : Only 'WA' state


    grdvThird.DataSource = dvSecond;


    grdvThird.DataBind();


    }


}


 


 


 


Output


 


 



  << Prev: Filtering and Sorting Data Using DataView/DataTable Next: SQL Transaction and Locking >>
Aspnet Database Tutorial Home
Give feedback and win a prize.

 
   Printer Friendly
   Email to a friend
   Add to my Favourites    
  Download PDF version
   Report Bad Submissions
   Submit Feedback
 
  Delicious   Digg   Technorati   Blink   Furl   Reddit   Newsvine   Google Click each image to add
this page to each site.
 
 
Welcome Guest Signup
MEMBER'S PANEL
EMAIL
PASSWORD
Forgot your password?
New User? Click Here!
 
Resend Activation Email!
 
SEARCH
 
 
LINKS
conferencing audio
Video Surveillance
Skype vs. sipcall
Gift to Pakistan
 
ADVERTISEMENT
 
PARTNER LIST

More
 
 
 

Home | Login | About Us | Contact Us | Privacy Policy | Advertising