Thursday, December 22, 2011

DataViews in Asp.net

The data view is read only data,The view is giving security to the database in front end.As per .net Technologies we can create views in the front end depending on the data table class.Using data views we can filter the data based on requirement.In data view class we can store data table copy.The MS given all privileges to the data table but not to the data view class. The data view class filtering the rows using row filter property ,depending on the requirement we can create any number of sub views.Here i will show how to use the data view and bind the different kind of to grid view.For this i have taken three button and one grid view.
code behind:
SqlConnection cn = new SqlConnection("Data Source=\\SQLEXPRESS;Initial catalog=user;Integrated Security=true;");
cn.Open();
SqlDataAdapter ad=new SqlDataAdapter ("select*from emp",cn) ;
DataSet ds = new DataSet();
Datatable dt=new Datatable();
Dataview dv;
//page loading
ad.fill(ds,"emp");
dt=ds.Tables["emp"];
dv=dt.Defaultview;
//button1_click
gvemp.DataSource=dv;
gvemp.DataBind
//button2_click
dv.RowFilter="ename like'a%';
gvemp.DataSource=dv;
//button3_click
dv.RowFilter="ename like'b%';
gvemp.DataSource=dv;
The data view hold the data which is filtered or required based on condition.The data view has some properties like AllowDelete,AllowEdit and AllowNew .It gives the customized view of data table

No comments:

Bel