gridview分页,不使用sqldatasource控件 [英] gridview paging without using sqldatasource control

查看:71
本文介绍了gridview分页,不使用sqldatasource控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

gridview分页,不使用sqldatasource控件(带有vb代码的asp.net)

gridview paging without using sqldatasource control(asp.net with vb code)

推荐答案

为了手动分页Gridview,我们必须处理Gridview的PageIndexChanged事件。如果我们需要将Gridview的PageIndex更改为用户单击的页面并再次绑定Gridview。

首先选择gridview属性并选择pageing = true。



和背后的代码

protected void gvPaging_PageIndexChanging(object sender,GridViewPageEventArgs e)

{

gvPaging.PageIndex = e.NewPageIndex;

gvPaging.DataBind();

}



这就是你需要做的全部在Gridview中进行手动分页。



对于在Gridview中手动排序,我们需要处理Gridview的Sorting事件。以下是执行该操作的代码。



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();

}

}

私有字符串getSortDirectionString(SortDirection sortDireciton)

{

string newSortDirection = String.Empty;

if(sortDirection == SortDirection.Ascending)

{

newSortDirection =ASC ;

}

其他

{

newSortDirection =DESC;

}

返回newSortDirection

}
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
}


这篇关于gridview分页,不使用sqldatasource控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆