paging without sqlDataSource control..
-
hi every one, can anyone tell me how to do paging for gridView in asp.net without using the sqlDataSource control, on clicking next it has to show the next page, on clicking prev it has to show the previous page in the gridView control. just like the operation we get in sqlDataSource control. i'm fresher pls explain in detail. any links also will help me great.. thanks in advance dittu :)
-
hi every one, can anyone tell me how to do paging for gridView in asp.net without using the sqlDataSource control, on clicking next it has to show the next page, on clicking prev it has to show the previous page in the gridView control. just like the operation we get in sqlDataSource control. i'm fresher pls explain in detail. any links also will help me great.. thanks in advance dittu :)
Try following code.
//For paging a Gridview manually we have to handle the Gridview’s PageIndexChanged Event.
//In the event we need to change the PageIndex of Gridview to the page that user has clicked and again bind the Gridview.protected void gvPaging_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvPaging.PageIndex = e.NewPageIndex;
gvPaging.DataBind();
}//This is all you need to do to make manual paging in the Gridview.
//For manually sorting in Gridview we need to handle the Sorting event of Gridview. Here is the code to do it.protected void gvSorting_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable dtSortTable = gvSorting.DataSource as DataTable;if (dtSortTable != null)
{
DataView dvSortedView = new DataView(dtSortTable);
dvSortedView.Sort = e.SortExpression + " " + getSortDirectionString(e.SortDirection);gvSorting.DataSource = dvSortedView; gvSorting.DataBind();
}
}private string getSortDirectionString(SortDirection sortDireciton)
{
string newSortDirection = String.Empty;
if(sortDirection== SortDirection.Ascending)
{
newSortDirection = "ASC";
}
else
{
newSortDirection = "DESC";
}
return newSortDirection
}HTH
Jinal Desai - LIVE Experience is mother of sage....