我下载AspNetPager不知道对DataList如何进行分页。我想知道后台代码是什么。 DataTable dt = GetTop.GetAllProduct(s);
PagedDataSource pds = new PagedDataSource();
this.AspNetPager1.RecordCount = dt.Rows.Count;
pds.CurrentPageIndex = this.AspNetPager1.CurrentPageIndex - 1;
pds.DataSource = dt.DefaultView;
this.DataList1.DataSource = pds;
this.DataList1.DataBind();
if (this.DataList1.Items.Count < 0)
{
this.div1.Visible = true;
Label18.Text = "暂无数据";
this.div11.Visible = false;
}
else {
this.div1.Visible = false;
this.div11.Visible = true;
}应该如何修改
PagedDataSource pds = new PagedDataSource();
this.AspNetPager1.RecordCount = dt.Rows.Count;
pds.CurrentPageIndex = this.AspNetPager1.CurrentPageIndex - 1;
pds.DataSource = dt.DefaultView;
this.DataList1.DataSource = pds;
this.DataList1.DataBind();
if (this.DataList1.Items.Count < 0)
{
this.div1.Visible = true;
Label18.Text = "暂无数据";
this.div11.Visible = false;
}
else {
this.div1.Visible = false;
this.div11.Visible = true;
}应该如何修改
解决方案 »
- 网站内的admin文件夹怎样才能让管理员进入?
- asp.net做网络应用系统
- 自定义的验证控件在FormView的EditItemTemplate中无法显示ErrorMessage
- ASP.NET 关于<object>的问题
- jQuery中lazyload问题
- xml文件中,到底什么是“XML架构信息”?
- 如何设置datagrid的列,让他不折行,就是nowrap那种格式
- 在asp.net中原来用的access,现在改为连接到sql server卡壳了?这老没办法登录,帮忙看看问题在何处?
- 急救(试题):WEB服务使用的三种技术是什么?
- 对《ASP.net入门经典》和《ASP.net从入门到精通》两本书的看法
- 如何设置IIS的权限
- JS中如何取后台属性值
rp_datalist.DataSource = cc.GetCompanyList(AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, " T_4012 DESC,T_4001 DESC ", _cond, out rowcount);
rp_datalist.DataBind();
GridView gv = new GridView();
AspNetPager1.RecordCount = rowcount;
/// <summary>
/// 获取记录数
/// </summary>
/// <param name="table"></param>
/// <param name="cond">格式:Where ...</param>
/// <returns></returns>
public int GetRowCount(string table, string cond)
{
int rowcount = 0;
string query = string.Format("Select count(*) From {0} {1}", table, cond);
using (IDataReader reader = DbHelper.ExecuteReader(CommandType.Text, query))
{
if (reader.Read()) rowcount = reader.GetInt32(0); return rowcount;
}
}
/// <summary>
///
/// </summary>
/// <param name="table"></param>
/// <param name="rowpage"></param>
/// <param name="rowcount"></param>
/// <param name="orderFid"></param>
/// <param name="Conditions"></param>
/// <returns></returns>
public DataTable GetinfoList(string table, int rowpage, int rowcount, string orderFid, string Conditions)
{ string query = "Select * From "
+ "(Select *,ROW_NUMBER() OVER(ORDER BY {2}) as RowNum From {4} {3}) as newTable "
+ "Where (RowNum BETWEEN ({0}) AND ({1}))";
query = string.Format(query, (rowpage - 1) * rowcount + 1, rowpage * rowcount, orderFid, Conditions, table); //string query = "Select top {0} * From {1} {2} and id not in(Select top {3} id From {1} {2} Order by {4}) Order by {4}";
//query = string.Format(query, rowcount, table, Conditions, (rowpage - 1) * rowcount + 1, orderFid);
return DbHelper.ExecuteTable(CommandType.Text, query); }
{
if (!IsPostBack)
{
UserCheck.CheckLoginUserVoid("../");
CardsView();
}
}
protected void CardsView()
{
if (Session["company_id"] != null)
{
int cid = Convert.ToInt32(Session["company_id"]);
var cardList = cardManage.GetAllCardsByProc(cid, anpCardList.PageSize, anpCardList.CurrentPageIndex,1);
anpCardList.RecordCount = cardList.Count;
this.rptCards.DataSource = cardList;
this.rptCards.DataBind();
}
}
//---数据范访问层
/// <summary>
/// 存储过程分页,全部数据
/// </summary>
/// <param name="c_cid">当前用户ID</param>
/// <param name="pageSize">每页显示行数</param>
/// <param name="pageIndex">页码,第n页</param>
/// <param name="c_sid">状态ID,[1表示正常],[2表示已删除]</param>
/// <returns></returns>
public static IList<MuCard> GetAllCardsByProc(int c_cid, int pageSize, int pageIndex,int c_sid)
{
string procText = ConfigurationManager.AppSettings["Pages"].ToString();
IList<MuCard> cardList = new List<MuCard>();
MuCard card = null;
SqlParameter[] pars = new SqlParameter[]
{
new SqlParameter("@pageSize",pageSize),
new SqlParameter("@pageIndex",pageIndex),
new SqlParameter("@c_cid",c_cid),
new SqlParameter("@c_sid",c_sid)
};
using (SqlDataReader dr = SqlHelper.ExecProcdureReturnDataReader(procText,CommandType.StoredProcedure,pars))
{
while (dr.Read())
{
card = new MuCard();
card.CID = Convert.ToInt32(dr[0]);
card.C_Name = dr[1].ToString();
card.C_ComName = dr[2].ToString();
card.C_Tel = dr[3].ToString();
card.C_Mobile = dr[4].ToString();
card.C_GID =Convert.ToInt32( dr[5]);
cardList.Add(card);
}
}
return cardList;
}
/// 分页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void anpCardList_PageChanged(object sender, EventArgs e)
{ CardsView();
}
<webdiyer:AspNetPager ID="anpCardList"
PageSize="15" runat="server" Visible="true"
ShowPageIndex="true"
FirstPageText="首页"
LastPageText="尾页"
AlwaysShow="True"
NextPageText="下一页"
PrevPageText="前一页"
ShowPageIndexBox="Always"
ShowNavigationToolTip="True"
onpagechanged="anpCardList_PageChanged"
MoreButtonClass=""
NumericButtonCount="5"
NumericButtonType="Image"
PageIndexBoxType="DropDownList">
</webdiyer:AspNetPager>
{
PagedDataSource pd = new PagedDataSource();
pd.AllowPaging = true;
pd.PageSize = this.AspNetPager1.PageSize;
pd.CurrentPageIndex = this.AspNetPager1.CurrentPageIndex - 1; this.AspNetPager1.RecordCount = list.Count; pd.DataSource = list;
this.DataList1.DataSource = pd;
this.DataList1.DataBind();
}