Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
gridview paging without using sqldatasource control(asp.net with vb code)
Posted

1 solution

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.
firstly select gridview property and select pageing=true.

and code behind
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
}
 
Share this answer
 
Comments
Member 10220152 17-Oct-13 23:18pm    
I use gvPaging_PageIndexChanging event but this isn't convenient.This isn't change new page index.
manvendra patel 18-Oct-13 1:00am    
fire gvPaging_PageIndexChanged event not gvPaging_PageIndexChanging event.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900