日期:2014-05-18  浏览次数:20391 次

怎么实现无组件翻页?
aspx.cs中的代码是这样的:
C# code
protected string showInfo(int id)
    {
        string sql = "select top 5 * from  context where listid=" + id + "";               
        string tbody = "";
        OleDbDataReader my_reader;
        OleDbCommand my_comm = new OleDbCommand();
       
        my_comm.CommandText= sql;
        my_comm.CommandType = CommandType.Text;
        my_comm.Connection = my_conn;
        my_conn.Open();
        my_reader = my_comm.ExecuteReader();
        while (my_reader.Read())
        {
            tbody += "<TD style=OVERFLOW: hidden; TEXT-OVERFLOW: ellipsis noWrap align=left width=100% height=26>";
            tbody += "<a href=show.aspx?id=" + my_reader["id"].ToString() + ">" + my_reader["title"].ToString() + " </a></TD></TR>";
            
        }
        my_reader.Close();
        my_conn.Close();
        return tbody;
    }

在页面用<%=showInfo%>调用上面的代码进行显示。但是怎么才能翻页显示呢?高手指点,谢谢!!

------解决方案--------------------
int PageRows = pageSize; //每页显示行数
int TotalPages = (TotalRows % PageRows == 0) ? TotalRows / PageRows : (TotalRows / PageRows) + 1; //确切页数
if (cPage < 1) cPage = 1;
if (cPage > TotalPages) cPage = TotalPages;
//构造查询字符串
string realSqlStr = "Select * FROM (select ROW_NUMBER()Over(" + OrderFied + ") as rowId," + sqlStr + " ) as mytable where rowId between " + ((cPage - 1) * pageSize + 1) + " and " + (cPage * pageSize >= TotalRows ? TotalRows : cPage * pageSize);
------解决方案--------------------
http://www.google.cn/search?q=%E7%BF%BB%E9%A1%B5%E5%AD%98%E5%82%A8%E8%BF%87%E7%A8%8B&rls=com.microsoft:zh-cn:IE-SearchBox&ie=UTF-8&oe=UTF-8&sourceid=ie7&rlz=1I7KCTA
------解决方案--------------------
CREATE PROCEDURE GetCustomDataPage 
@pageSize int,
@pageIndex int,
@pageCount int output, 
@recordCount int output 
AS 
declare @SQL varchar(1000)
select @recordCount=count(*) from products
set @pageCount=ceiling(@recordCount*1.0/@pageSize)
if @pageIndex = 0 or @pageCount<=1
set @SQL='select top '+str(@pageSize)+' productID,productName, unitPrice from products order by productID asc'
else if @pageIndex = @pageCount -1
set @SQL='select * from ( select top '+str(@recordCount - @pageSize * @pageIndex)+' productID,productName, unitPrice from products order by productID desc) TempTable order by productID asc'

else set @SQL='select top '+str(@pageSize) +' * from ( select top '+str(@recordCount - @pageSize * @pageIndex)+' productID,productName, unitPrice from products order by productID desc) TempTable order by productID asc' 

exec(@SQL)
GO
------解决方案--------------------
你在反页的链接里面传参数 比如 <a hreft="default.apx?PageNum=3 ">下一页</a>
这样当你点击下一页的时候 你把这个参数取下来,然后再使用楼上的反页存储过程进行反页;关于然后把连接修改为<a hreft="default.apx?PageNum=4 ">下一页</a> 如果有的话