Filtering,Sorting, Removing records From data table in Asp.Net using Dataview
In ASP.Net we are using dataset as a collection of tables. By using dataset we assign the table data to ASP.NET controls(Gridview,Repeater .. etc).
Sometimes we want to filter the data before assign to the controls. In this case what can we do. In Asp.Net we have a super object to do this, that is called Dataview.
By using Dataview object we can filer the data of DataTable. Not only filtering, we can sort the table data and we can find some specified rows also.
Advantages of Dataview:
-->Filtering the table data
-->Sorting the table data
-->we can find some specified rows
Filtering that table data:
If we want to show the table data based on some filtering, we can show by using dataview object instead of putting the condition in Sql Query.
Eg: If we have table called emp where we store the all employee data with their salary. But we want to show the list of employees who has salary more than 5000.
Then put condition like this
dv.RowFilter = "salary>50000" ‘where dv is the dataview object
Dim con As New SqlConnection("your database connection string")
Dim sqldad As New SqlDataAdapter("select * from emp1", con)
Dim ds As New DataSet
sqldad.Fill(ds)
'Filtering using Dataview
Dim dv As New DataView
'fill dataview object using dataset
dv = ds.Tables(0).DefaultView
'row filter
dv.RowFilter = "salary>50000"
gv1_filter.DataSource = dv
gv1_filter.DataBind()
In this way we can filter the data by using dataview object.
Next >>
Subscribe
Filter by APML