谢谢大家,我把我的源码贴一下,希望大家指出错误之处
页面载入的代码:
private void Page_Load(object sender, System.EventArgs e)
{
  if(!this.IsPostBack)
  {   
     dataView1 = new DataView();
     dsYdcs1 = new ChinaNet.dsYdcs();
     ...
     dataView1.Table = dsYdcs1.T_ydsc;
     DataGrid1.DataSource=dataView1.Table;
     DataGrid1.DataBind();
     DataGrid1.CurrentPageIndex=0;
}
}
查询返回时绑定的代码:
sqlDataAdapter1.Fill(dsYdcs1);
this.Page.DataBind();
DataGrid1.DataBind();
分页代码:
DataGrid1.CurrentPageIndex = e.NewPageIndex;
sqlDataAdapter1.Fill(dsYdcs1);
DataGrid1.DataSource = dsYdcs1;
DataGrid1.CurrentPageIndex = e.NewPageIndex;
DataGrid1.DataBind();
排序代码:
dataView1.Sort = e.SortExpression + " DESC";
sqlDataAdapter1.Fill(dsYdcs1);
DataGrid1.DataBind();

解决方案 »

  1.   

    看你的代码,排序应该也不会显示吧?因为你查询和排序都没有设置DataGrid1的数据源。我的一个建议:在你的PAGE中添加成员SORT和FILTER分别表示排序和过滤条件,当你点击排序、过滤、分页时只是简单的设置相关属性(分页则只要设置CURRENTPAGEINDEX就可以了)而不要做任何操作,然后添加一个PRERENDER事件代理,在PRERENDER中,实现数据源的设置与绑定等操作。
      

  2.   

    一般都是手动配置数据源的,你是设计器设置的吗?否则应该设置数据源。
    --------------------------
    sqlDataAdapter1.Fill(dsYdcs1);
    this.Page.DataBind();
    ====我好象记得使用了Page.DataBind()就不需要使用DataGrid1.DataBind();其实通常一般都不使用这句的;
    DataGrid1.DataBind();
      

  3.   

    to triout(笨牛) :
        我大概明白了你的意思,但是过滤条件该怎样定义呢?比如说,我该怎样定义针对哪个列进行排序这个公有的条件呢?