不使用“DataSourceControl DataSource”的情况下如何分页和排序
2007-04-12 02:46
399 查看
不使用“DataSourceControl DataSource”的情况下如何分页和排序
If you set AllowPaging="true" or AllowSorting="true" on a GridView control without using a DataSourceControl DataSource (i.e. SqlDataSource, ObjectDataSource), you will run into the following errors:When changing the page on the GridView control:
The GridView 'GridViewID' fired event PageIndexChanging which wasn't handled.
When clicking a column name to sort the column on the GridView control:
The GridView 'GridViewID' fired event Sorting which wasn't handled.
As a result of not setting the DataSourceID property of the GridView to a DataSourceControl DataSource, you have to add event handlers for sorting and paging.
<asp:GridView ID="gridView" OnPageIndexChanging="gridView_PageIndexChanging" OnSorting="gridView_Sorting" runat="server" />
private string ConvertSortDirectionToSql(SortDirection sortDireciton)
{
string m_SortDirection = String.Empty;
switch (sortDirection)
{
case SortDirection.Ascending:
m_SortDirection = "ASC";
break;
case SortDirection.Descending:
m_SortDirection = "DESC";
break;
}
return m_SortDirection
}
protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gridView.PageIndex = e.NewPageIndex;
gridView.DataBind();
}
protected void gridView_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable m_DataTable = gridView.DataSource as DataTable;
if (m_DataTable != null)
{
DataView m_DataView = new DataView(m_DataTable);
m_DataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(e.SortDirection);
gridView.DataSource = m_DataView;
gridView.DataBind();
}
}
相关文章推荐
- Gridview排序与分页-不使用“DataSourceControl DataSource”的情况下如何分页和排序 ...
- 不使用“DataSourceControl DataSource”的情况下如何分页和排序
- 不使用“DataSourceControl DataSource”的情况下如何分页和排序
- Tricks(二十七)—— 如何在不使用 np.argsort 的情况下获得排序后元素的下标
- SAS如何在不排序的情况下使用by语句
- Asp.net学习笔记----使用GridView+ObjectDataSource进行自定义分页排序
- C#拼接SQL语句,SQL Server 2005+,多行多列大数据量情况下,使用ROW_NUMBER实现的高效分页排序
- C#如何使用分页控件[tabControl]
- ListView加DataPager在不使用LinqDataSource(DataSourceID)时如何动态分页
- 转:本文介绍了在使用DevExpress GridControl的开发过程中如何设置列数据的格式。
- 解决使用HIBERNATE对ORACLE数据库中数据进行排序分页错乱的问题
- 如何查看redis内存使用情况
- 如何SQL Server 2005实现使用CLR函数实现字符串排序
- mybatis分页插件的使用(电商项目前端动态查询排序)
- 嵌入式 linux系统如何查看内存使用情况详解
- C# GridView 在使用分页时,如何不显示底部自动添加的分页风格
- 如何快速估计/估算Linux VPS的月流量使用情况(不用安装MRTG等流量监控软件) - LinuxVPS使用教程 - 国外/美国服务器租用
- js:数组重排序问题:如何使用sort()方法按数值的大小进行升序或降序排列
- 在没有显示器和IP未知的情况下如何使用树莓派
- 如何检查Oracle表空间使用情况