Thursday, January 3, 2008

GridView Paging and Sorting in ASP.NET 2.0 without SqlDataSource

When displaying large amounts of data it's often best to only display a portion of the data, allowing the user to step through the data ten or so records at a time. Additionally, the end user's experience can be enhanced if they are able to sort the data by one of the columns. Creating a pageable, bi-directional sortable DataGrid in ASP.NET 1.x was possible, but required creating two event handlers and writing, at minimum, a half dozen lines of code. The good news is that with ASP.NET 2.0 you can create a pageable, bi-directional sortable DataGrid without writing a single line of code!

View the following Link to See the Example of Gridview Paging and Sorting in ASP.NET 2.0 with SQLDataSource GridView Paging

or

The follwoing Shows how to do Paging and Sorting without SQLDataSource,

--> First Change the AllowPaging and AllowSorting Properties to True for GridView.

For Paging,

on Page_Load,

Dim sqlconn As New SqlConnection("data source=;database=;uid=;pwd=")
Dim da As New SqlDataAdapter("select login,firstname,lastname from users", sqlconn)
Dim ds As New DataSet
da.Fill(ds, "users")
GridView1.DataSource = ds.Tables(0)
GridView1.DataBind()

GridView Has an Event Called PageIndexChanging , in this Event Procedure Write the following code

GridView1.PageIndex = e.NewPageIndex

No comments: