当前位置: 代码迷 >> ASP.NET >> repeater 所有数据排序,不是当前页解决办法
  详细解决方案

repeater 所有数据排序,不是当前页解决办法

热度:2263   发布时间:2013-02-25 00:00:00.0
repeater 所有数据排序,不是当前页
参照网上做了repeater 排序,但是当前页的排序,如果要对全部数据怎么排序啊? 
我用的da.Fill(ds,AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, table);
这个方法,

JScript code
function Getsort(obj)    {        // document.all.sortfield.value=obj;       document.getElementById("sortfield").value=obj;               if(document.getElementById("sortstring").value=='ASC')         {               document.getElementById("sortstring").value='DESC';         }         else if(document.getElementById("sortstring").value=='DESC')         {               document.getElementById("sortstring").value='ASC';         }        __doPostBack('LinkButton1','');     }

C# code
后台代码:  public DataSet GetSoftTj(AspNetPager AspNetPager1, string condition)    {        SqlConnection conn = db.CreateConnection();        string sql = @"select a.Title,COUNT(a.Title) as shu from Product a,ProductComputer b,                           Computer c where a.Product_Idn=b.Product_Idn and b.Computer_Idn=c.Computer_Idn and a.title like N'%"+condition +"%' group by Title";        SqlDataAdapter da = new SqlDataAdapter(sql,conn);        DataSet ds = new DataSet();        try        {            da.Fill(ds,AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "table2");        }        catch (SqlException ex)        {            throw new Exception(ex.Message, ex);        }        return ds;    } private void Bind(string str)    {        if (Request.Cookies["text1"] != null)        {            DataSet ds = bl.GetSoftTj(AspNetPager1,Request.Cookies["text1"].Value.ToString());            DataView dv = ds.Tables[0].DefaultView;            dv.Sort = str;            Repeater1.DataSource = dv;            Repeater1.DataBind();        }        else        {        }    } private void BindAspNetPager()    {        if (Request.Cookies["text1"] != null)        {            AspNetPager1.RecordCount = bl.SoftCountTj(Request.Cookies["text1"].Value.ToString());        }        else        {        }    }    protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)    {        AspNetPager1.CurrentPageIndex = e.NewPageIndex;        Bind("");    }protected void LinkButton1_Click(object sender, EventArgs e)   {       string sortfield1 = sortfield.Value;       string sortstring1 = sortstring.Value;       string a = sortfield1 + " " + sortstring1;       if (a != "" && a != null)       {           Bind(a);       }   }


------解决方案--------------------------------------------------------
直接排序就可以了。看你写那么复杂。用存储过程也可以的!
------解决方案--------------------------------------------------------
直接SQL语句查询时就排序啊,搞这么复杂。
select * from TABLE_A order by ID (按ID顺序排列)

select * from TABLE_A order by ID desc (按ID倒叙排列)
------解决方案--------------------------------------------------------
你要分页排序也可以:
select top pagesize(当前显示页数) * from (select top pagesize*pageindex(pageindex当前第几页) * from TABLE_A order by ID)a order by ID desc
  相关解决方案