PDA

View Full Version : صفحه بندی مانند گوگل



bftarane
شنبه 05 بهمن 1392, 13:37 عصر
سلام.
من الآن مثلاً یه کلمه رو در گوگل سرچ زدم در ابتدا صفحه بندی به شکل زیر هست
115898
حالا روی صفحه 9 که کلیک می کنم صفحه بندی به شکل زیر تبدیل میشه
115899
یعنی حالا صفحات 1 و 2 و 3 نشون داده نمی شن و شماره صفحات از 4 شروع میشه

ممنون می شم راهنمایی کنید که چطور میشه صفحه بندی رو به شکل بالا انجام داد.

من صفحه بندی رو به روش لینک زیر انجام می دم
http://aspsnippets.com/Articles/Implement-Paging-in-Repeater-control-in-ASPNet.aspx

ولی چون با اکسس کار می کنم کدهای بالا رو به شکل زیر تطبیق دادم (چون تا جایی که من اطلاع دارم در اکسس خبری از store procedure و دستور rownumber نیست)


DALBase DBase = new DALBase();
private int PageSize = 9;
protected void Page_Load(object sender, EventArgs e)
{
int PdCatId = 0;
if (Request.QueryString["PdCatId"] != null)
{
PdCatId = Convert.ToInt32(Request.QueryString["PdCatId"]);
if (!IsPostBack)
{
this.GetProductsPageWise(0, PdCatId);
GetMeta(PdCatId);
lbl_count.Text = GetCountByCat(PdCatId).ToString();
}
}
else
{
if (!IsPostBack)
{
this.GetProductsPageWise(0, PdCatId);
lbl_count.Text = GetCount().ToString();
}
}

}
private void GetProductsPageWise(int pageIndex, int cat)
{
string sql = "";
if (cat ==0)
{
sql = "Select TOP " + PageSize + " * From (Select TOP " + (GetCount(cat) - ((pageIndex - 1) * PageSize)) + " * From tbl_Pd where Remove=@Remove Order By Pd_ID ASC) Order By Pd_ID DESC";

}
else
{
sql = "Select TOP " + PageSize + " * From (Select TOP " + (GetCount(cat) - ((pageIndex - 1) * PageSize)) + " * From tbl_Pd where Pd_CatId=@Pd_CatId and Remove=@Remove Order By Pd_ID ASC) Order By Pd_ID DESC";

}

OleDbDataReader dr = DBase.ExecuteReader(System.Data.CommandType.Text, sql, new OleDbParameter[]{
new OleDbParameter("@Pd_CatId",cat),
new OleDbParameter("@Remove",false)
});
rpt_Pd.DataSource = dr;
rpt_Pd.DataBind();
int recordCount = GetCount(cat);
this.PopulatePager(recordCount, pageIndex);
}
public int GetCount(int cat)
{
if (cat==0)
{
object retVal = DBase.ExecuteScaler(System.Data.CommandType.Text, "Select Count(*) As TotRows From tbl_Pd where Remove=@Remove", new OleDbParameter[]{
new OleDbParameter("@Remove",false)
});
if (retVal != null)
return Convert.ToInt32(retVal);
else
return 0;
}
else
{
object retVal = DBase.ExecuteScaler(System.Data.CommandType.Text, "Select Count(*) As TotRows From tbl_Pd where Remove=@Remove and Pd_CatId=@Pd_CatId", new OleDbParameter[]{
new OleDbParameter("@Remove",false),
new OleDbParameter("@Pd_CatId",cat)
});
if (retVal != null)
return Convert.ToInt32(retVal);
else
return 0;
}

}
private void PopulatePager(int recordCount, int currentPage)
{
double dblPageCount = (double)((decimal)recordCount / Convert.ToDecimal(PageSize));
int pageCount = (int)Math.Ceiling(dblPageCount);
List<ListItem> pages = new List<ListItem>();
if (pageCount > 0)
{
for (int i = 1; i <= pageCount; i++)
{
pages.Add(new ListItem(i.ToString(), i.ToString(), i != currentPage));
}
}
rptPager.DataSource = pages;
rptPager.DataBind();
}

protected void Page_Changed(object sender, EventArgs e)
{
int PdCatId = 0;
int pageIndex = int.Parse((sender as LinkButton).CommandArgument);
if (Request.QueryString["PdCatId"] != null)
{



PdCatId = Convert.ToInt32(Request.QueryString["PdCatId"]);


this.GetProductsPageWise(pageIndex, PdCatId);
}
else
{


this.GetProductsPageWise(pageIndex, PdCatId);
}
}



public int GetCount()
{
object retVal = DBase.ExecuteScaler(System.Data.CommandType.Text, "select COUNT(*) from tbl_Pd where Remove=false", new OleDbParameter[]{

});
if (retVal != null)
return Convert.ToInt32(retVal);
else
return 0;
}
public int GetCountByCat(int Pd_CatId)
{
object retVal = DBase.ExecuteScaler(System.Data.CommandType.Text, "select COUNT(*) from tbl_Pd where Pd_CatId=@Pd_CatId and Remove=false", new OleDbParameter[]{
new OleDbParameter("@Pd_CatId",Pd_CatId)
});
if (retVal != null)
return Convert.ToInt32(retVal);
else
return 0;
}

Mohammad_dn
شنبه 05 بهمن 1392, 14:19 عصر
http://barnamenevis.org/showthread.php?433125

اینم یه Paging برای شما

همون چیزیه که میخوای

bftarane
یک شنبه 06 بهمن 1392, 08:51 صبح
مرسی از پاسختون. برای تستش باید وقت بیشتری بزارم چون ظاهراً بانک رو نزاشته بودید. و البته از rownumber استفاده شده بود که در اکسس ظاهراً وجود نداره.
ولی یه لینک دیگه پیدا کردم که دقیقاً کاری که من می خواستم رو انجام داده بود
http://www.codeproject.com/Tips/377207/Custom-paging-like-Google-paging
ممنون.