不使用“DataSourceControl DataSource”的情况下如何分页和排序
2009-01-02 22:54
555 查看
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();
}
}
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)时如何动态分页
- 如何在一个已排序的NSArray中搜索某一特定字符串?答案是使用CFArray自带的搜索功能
- 如何使用DDMS Heap查看Android应用内存情况
- 如何查看redis内存使用情况
- mybatis分页插件的使用(电商项目前端动态查询排序)
- js:数组重排序问题:如何使用sort()方法按数值的大小进行升序或降序排列
- 在没有显示器和IP未知的情况下如何使用树莓派
- 如何SQL Server 2005实现使用CLR函数实现字符串排序
- 转:本文介绍了在使用DevExpress GridControl的开发过程中如何设置列数据的格式。
- 如何检查Oracle表空间使用情况
- C# GridView 在使用分页时,如何不显示底部自动添加的分页风格
- 如何在Windows Server 2008 R2没有磁盘清理工具的情况下使用系统提供的磁盘清理工具