AspNetPager的使用
这个控件有人说在2.0下面不能使用,试了一下,看来说法有误哦!仍然可以使用,方法也一样。下面把方法说明一下。
1.将AspNetPager控件放入工具箱的方法是右键点击工具箱,选择添加项目,然后刘览相关dll文件。
2.控件外观的设定
xml:namespace prefix =
webdiyer />
其实,一些属性我也不懂是什么,ShowCustomInfoSection大约是一个安放自定义文本的东东。PageSize设定分页显示的记录笔数。OnPageChanged事件调用后台的方法。
3.设定总的记录笔数在Page_L
oad事件里面
this.AspNetPager1.RecordCount=pager.GetAuthorsRowsCount("ahthors");
这里计算记录总笔数的方法是:
///
///通用方法用于计算记录笔数
/// ///
///
publicintExecuteCount(stringmySql)
{
SqlCommandmyCmd=newSqlCommand(mySql,myConn);
myCmd.CommandText=mySql;
try
{
myConn.Open();
return(int)myCmd.ExecuteScalar();
}
catch(Exceptionex)
{
return-99;
}
finally
{
myCmd.Dispose();
myConn.Close();
}
}
///
///得到当前记录的笔数
///
///
///
publicintGetAuthorsRowsCount(stringtablename)
{
stringsql="selectcount(*)fromauthors";
returnthis.ExecuteCount(sql);