动态网格视图中的分页和排序 [英] pagging and sorting in dyanamic gridview
本文介绍了动态网格视图中的分页和排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们如何使用c#在动态创建的gridview中进行pag和排序?
how we will do pagging and sorting in dynamic created gridview using c#?
推荐答案
您使用Grid的PageIndexChanging事件.
you use PageIndexChanging Event of Grid .
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
// bind grid using Select Query.
}
hope this will help you, if not please post it.
好,我的亲爱的朋友,在Gridview中,属性设置允许sorting = true
然后编写此代码.
Ok , My dear Friends, Just in Gridview Properties set allow sorting=true
then write this code.
private string ConvertSortDirectionToSql(SortDirection sortDirection)
{
string newSortDirection = String.Empty;
switch (sortDirection)
{
case SortDirection.Ascending:
newSortDirection = "ASC";
break;
case SortDirection.Descending:
newSortDirection = "DESC";
break;
}
return newSortDirection;
}
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable dataTable = GridView1.DataSource as DataTable;
if (dataTable != null)
{
DataView dataView = new DataView(dataTable);
dataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(e.SortDirection);
GridView1.DataSource = dataView;
GridView1.DataBind();
}
}
好的,这肯定会对你有帮助.
ok, this will be definitely help u.
这篇关于动态网格视图中的分页和排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文