Library tutorials & articles
Web Forms DataGrid and DataSet Programming
Introduction
This is a working C# .NET program that demonstrates how to integrate most of the features of the DataGrid and DataSet in a single project including select, insert, update, delete, confirm delete, sort, filter and page. This is a work in progress and feedback is an important factor in improving this tutorial. Please report any bugs and I will try to fix them.
A few general concepts are presented here and represent my best understanding of how the DataSet and DataGrid works.
The SqlDataAdapter provides a bridge between the DataSet and the data source.
Calling Fill, refreshes the data in the DataSet. Calling Update, attempts to
commit any changes in the DataSet. The SqlDataAdapter wizard simplifies building
of data driven forms by automatically generating UPDATE, INSERT and DELETE statements from your SqlDataAdapter SELECT statement. By default, the UPDATE statement implements an Optimistic Concurrency scheme that looks for an unaltered
row on UPDATE.
The DataSet can encapsulate a parent child hierarchy of zero or more data
tables. The DataSet also stores its state, storing both the @original values
and any new uncommitted values. These original values are used to enforce "Optimistic
Concurrency" by searching for unaltered rows on UPDATE. Unlike the DataGrid,
the DataSet does _not_ persist itself on post back.
The DataGrid is used to display data in the HTML page. If DataGrid paging is not enabled, the DataGrid will display all of the rows in the appropriate table in the corresponding DataSet. To enable sorting and filtering, the DataGrid is bound to a View, not to the DataSet.
The View is used to sort and filter data in the DataSet before it is passed to the DataGrid using the properties:
view.RowFilter
view.Sort
The data path looks like this:
DataBase --> DataSet --> View --> DataGrid
Related articles
Related discussion
-
Chart insertation in a windows form...
by pdhanik (1 replies)
-
Writing Plugin-Based Applications
by haneen (12 replies)
-
filter dataview on datagrid in datalist
by janetb (0 replies)
-
ASP .NET Web Service Error Message ,"Client found response content type of 'text/html; charset=utf-8', but expected 'text/xml'."
by salil15august (1 replies)
-
hey developers out there
by pitsophera (0 replies)
Related podcasts
-
Writing FaceBook Applications with .NET - Interview with Mel Sampat, author of Outsync
In this episode, Scott talks with Mel Sampat, a Program Manager at Microsoft who's written OutSync, an application that syncs faces between Outlook, Facebook, and indirectly Windows SmartPhones. They chat about what it takes to write your own FaceBook application using ASP.NET or WinForms.
Events coming up
-
Mar
15
DevWeek 2010
London, United Kingdom
DevWeek is Europe’s leading independent conference for software developers, database professionals and IT architects, and features expert speakers on a wide range of topics, including .NET 4.0, Silverlight 3, WCF 4, Visual Studio 2010, REST, Windows Workflow 4, Thread Synchronization, ASP.NET 4.0, SQL Server 2008 R2, LINQ, Unit Testing, CLR & C# 4.0, .NET Patterns, WPF 4, F#, Windows Azure, ADO.NET, Entity Framework, Debugging, T-SQL Tips & Tricks, and more.
Vjero
hi
hey ppl i m inserting some data manually in a dataview then i m sorting that dta via dataview.sort , sorting is taking place perfectly here but when i embed this data into a word document then i found that data is not in sorted order as this supposed to be but it is in order in which it had typed...........so guys if u have have any solution of this problem then plz mail me at aman_105@rediffmail.com
hello
I am converting C#.net code into vb.net code .
Sorting ASC or DESC is not working .
while degugging ,code work fine but i think some how dataset is not getting refreshed.
I have commented these line 'view.RowFilter = lastFilter' .Is it require for sorting
Execpt that everything is same
please help me out .
Thanks
Hi.
I dont know if this only a problem of mine, but when I hit a sort column the DataGridSortCommand happens twice.
Should this happen? In my case it happens and so all the code in that event doesnt work properly...
Could some help me out on this one?
TIA,
C.C.
Jeff,
Thanks a bunch! I am new to ASP.NET programming and it was having a devil of a time getting my datagrid to sort -- your example provided the one missing link: the DataSource property should have been set to the view and not the dataset! Tanx again.
--Babak
This thread is for discussions of Web Forms DataGrid and DataSet Programming.