排序是自己写的..不是DataGrid自带的那种..是用一个下拉列表外加一个Button做的..我想分页后还能排序怎么做??分页程序是用的AspNetPager..public static DataSet Bind_Order_By_Hit(string Class,int PageTotal,int PageSize)
    {
        string Sql = "Select * From VV_Video Where Video_Class='" + Class + "' Order By Video_Hit Desc";
        DataSet DS=DB_Operate.Get_DS(Sql);
        return DS;
    }    //按时间排序
    public static DataSet Bind_Order_By_Time(string Class, int PageTotal, int PageSize)
    {
        string Sql = "Select * From VV_Video Where Video_Class='" + Class + "' Order By Video_Time Desc";
        DataSet DS = DB_Operate.Get_DS(Sql);
        return DS;
    }    //按大小排序
    public static DataSet Bind_Order_By_Size(string Class, int PageTotal, int PageSize)
    {
        string Sql = "Select * From VV_Video Where Video_Class='" + Class + "' Order By Video_Size Desc";
        DataSet DS = DB_Operate.Get_DS(Sql);
        return DS;
    }
string Video_Class=Request.QueryString["Video_Class"];
        string Num = this.Px_DropDownList.SelectedValue.ToString();
        switch (Num)
        {
            case "1":
                Video_DataGrid.DataSource = Create_Bind.Bind_Order_By_Hit(Video_Class, Video_AspNetPager.PageSize * (Video_AspNetPager.CurrentPageIndex - 1), Video_AspNetPager.PageSize);
                Video_DataGrid.DataBind();
                break;
            case "2":
                Video_DataGrid.DataSource = Create_Bind.Bind_Order_By_Time(Video_Class, Video_AspNetPager.PageSize * (Video_AspNetPager.CurrentPageIndex - 1), Video_AspNetPager.PageSize);
                Video_DataGrid.DataBind();
                break;
            case "3":
                Video_DataGrid.DataSource = Create_Bind.Bind_Order_By_Size(Video_Class, Video_AspNetPager.PageSize * (Video_AspNetPager.CurrentPageIndex - 1), Video_AspNetPager.PageSize);
                Video_DataGrid.DataBind();
                break;
        }

解决方案 »

  1.   

    将用户选择的条件存入htmlInputHidden中,按该条件从数据库中取值。
      

  2.   

    只有在用户点击“查询”按钮时才更新htmlInputHidden里的条件;
      

  3.   


    1.在頁面加一個htmlinputHidden;
    2.用戶點擊某一名稱進行排序時,將這個名稱記錄下來,放在htmlinputHidden中;
    3.看看你的數據庫中對應與這個名稱的是哪個字段,再按這個字段排序.例如:
    sql="select * from yourtable order by " & getField(htmlinputHidden.value)
    DataGrid1.datasource=sqlhelper.ExecuteDataset(strconnectionstring,CommandType.Text,sql)
    DataGrid1.databindfunction getField(byval str as string) as stringdim ret as stringselect case
      case "A"
      ret="FieldA"
      ...
    end  selectend function
      

  4.   

    function getField(byval str as string) as stringdim ret as stringselect case
      case "A"
      ret="FieldA"
      ...
    end  select
    end function-->
    function getField(byval str as string) as stringdim ret as stringselect case
      case "A"
      ret="FieldA"
      ...
    end  select
    return ret '返回排序字段
    end function