有没有演示程序,高手请帮忙
解决方案 »
- 求详细解释整条sql语句
- 问下网易博客的那种拖动效果是怎么实现的
- gridview更新数据
- DropDownList的重复项的问题
- asp.net如何获取客户端网卡NIC地址
- 散分,欢迎到刨坑网刨视频!
- 我现在有20+个网站须要发布已经有申请好相应的域名了,每一个网站都不大于10M用什么方法发布到Internet最好呢
- 在HTML中form 可以嵌套吗?如果可以,怎样引用里面的元素呢?
- 为什么我在webconfig中设置的都正确,但是无法和sqlserver相恋?
- 画图的问题,大家帮帮忙,给点思路,很着急呀~~~~
- 求助,想把x和y2张表的x.name和y.gname2字段合并捆绑
- 用foreach取出控件后如何定义属性?
这是详细的用法!!
我要的是用ObjectDataSource做数据源时,自定义分页的代码,具体过程是对象用一个方法访问分页存储过程,存储过程传回总记录数和指定页码的记录集,gridview将记录集显示。
http://community.csdn.net/Expert/topic/4543/4543542.xml?temp=.964596
当跳转页面时,动态改变List<T>不就可以了吗???
你要缓存的话,也是一样的。
例子:
public class User
{
private string mUserName = "";
private string mPassWord = "";public string UserName
{
get
{
retrun mUserName ;
}
set
{
mUserName = value;
}
}
public string PassWord
{
get
{
retrun mPassWord ;
}
set
{
mPassWord = value;
}
}
}
然后:
this.DataList.DataSouce = getuser();//return a List<User>;
this.DataList.DataBind();
在前台<%#...%>邦定.
在.net 2.0里只要实现了IEnumrable接口的数据类都可以直接作为数据源.
首先,他的AllowCustomPaging=true.即自行分页.
接下来VirtualItemCount记录的总数量.
最后在设置每页多少条.
就是你要的效果.不知道gridview是不是一样,但原理差不多.
string sql = @"SELECT ProductID, ProductName, QuantityPerUnit,
UnitPrice, UnitsInStock
FROM Products";
using (SqlConnection myConnection = new
SqlConnection(ConfigurationManager.ConnectionStrings[
"NWConnectionString"].ConnectionString))
{
// Place the data in a DataTable
SqlCommand myCommand = new SqlCommand(sql, myConnection);
SqlDataAdapter myAdapter = new SqlDataAdapter(myCommand);
myConnection.Open();
DataTable dt = new DataTable();
myAdapter.Fill(dt);
List<Product> results = new List<Product>();
int currentIndex = startRowIndex;
int itemsRead = 0;
int totalRecords = dt.Rows.Count;
while (itemsRead < maximumRows &&
currentIndex < totalRecords)
{
Product product = new Product();
product.ProductID =
Convert.ToInt32(dt.Rows[currentIndex]["ProductID"]);
product.ProductName =
dt.Rows[currentIndex]["ProductName"].ToString();
product.QuantityPerUnit =
dt.Rows[currentIndex]["QuantityPerUnit"].ToString();
if (dt.Rows[currentIndex]
["UnitPrice"].Equals(DBNull.Value))
product.UnitPrice = 0;
else
product.UnitPrice =
Convert.ToDecimal(dt.Rows[currentIndex]["UnitPrice"]);
if (dt.Rows[currentIndex]
["UnitsInStock"].Equals(DBNull.Value))
product.UnitsInStock = 0;
else
product.UnitsInStock =
Convert.ToInt32(dt.Rows[currentIndex]["UnitsInStock"]);
results.Add(product);
itemsRead++;
currentIndex++;
}
myConnection.Close();
return results;其中myAdapter.Fill(dt)这一句,对于大量记录,不是一样耗费资源么?
所以objectdatasource应当与datalist配合应用进行分页操作,这才是可行的办法.
我的BLOG:HTTP://ggdesign.meizu.net
希望大家多多指教。
==================