Grid View control in ASP.NET 2.0

ASP.Net 2.0 replaces the good old classic DataGrid control with the GridView control. Do you remember what all steps you used to take care of to allow the pagination in the data grid? ASP.NET 2.0 makes it simpler with the Grid View control.
This control is much like the DataGrid server control, but the GridView server control (besides offering many other new features) contains the built-in capability to apply paging, sorting, and editing of data with relatively little work on your part.
Following is a code snippet using the GridView control. This code builds a table from the Customers table in the Northwind with paging features.


<%@ Page Language=”VB” %>
<%@ Page Language=”VB” %>
<html>
<head runat=”server”>
<title>GridView Demo</title>
</head>
<body>
<form runat=”server”>
<asp:GridView ID=”GridView1” Runat=”server” AllowPaging=”True”
DataSourceId=”Sqldatasource1” />
<asp:SqlDataSource ID=”SqlDataSource1” Runat=”server”
SelectCommand=”Select * From Customers”
ProviderName=”System.Data.OleDb”
ConnectionString=”Provider=SQLOLEDB;Server=localhost;uid=sa;
pwd=password;database=Northwind” />
</form>
</body>
</html>



That’s all you have to do! Paging is enabled by setting the server control attribute AllowPaging of the GridView control:
<asp:GridView ID=”GridView1” Runat=”server” AllowPaging=”True”
DataSourceId=”SqlDataSource1” />


If you might have noticed all the processing of the above code is not included in runat=”server”. This means
We don’t need to write any server-side code to make this all work! Only some server controls needs to be included:
one control to get the data and one control to display the data.

Visit this msdn link for much more about GridView control
http://msdn.microsoft.com/msdnmag/issues/04/08/GridView/

No comments:

Followers

Powered by Blogger.