gridview分页(gridview分页显示)

http://www.itjxue.com  2023-02-10 11:19  来源:未知  点击次数: 

主从表显示从表的Gridview怎么实现分页

比如 有userInfo 和bookInfo 两张表

select * from userInfo inner join bookInfo on

userInfo.id=bookInfo.id

where userInfo.id between (PageNum-1)*PageSize and ((PageNum-1)*PageSize)+PageSize)

PageNum 用户翻到的当前页

PageSize 每页的最大行数

(PageNum-1)*PageSize 一个算法,只是算出当前页的第一条数据

((PageNum-1)*PageSize)+PageSize) 算出当前页的最后一条数据

最好的办法是 用 RowNumber在数据库里分页

如果是对Gridview 的数据源 dataset分页也可以(不过这样不科学。。。)

int beginPage=(PageNum-1)*PageSize; //翻页后的第一条数据

int endPage=((PageNum-1)*PageSize)+PageSize); //翻页后的最后一条数据

for(int i=beginPage;iendPage;i++)

{

赋值给一个新的dataset

}

然后把新的dataset交给 Gridview

如何实现 GridView 左右滑动分页的效果

gridview 实现横向分页滑动效果的两种实现方案

DisplayMetrics dm;

private void setValue() {

int count = gridAdapter.getCount();

int numColumns = (count % 2 == 0) ? count / 2 : count / 2 + 1;

LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(numColumns * dm.widthPixels / 5, LinearLayout.LayoutParams.WRAP_CONTENT);

gridView.setLayoutParams(params);

gridView.setColumnWidth(dm.widthPixels / 5);

// gridView.setHorizontalSpacing(hSpacing);

gridView.setStretchMode(GridView.NO_STRETCH);

gridView.setNumColumns(numColumns);

}

private void getScreenDen() {

dm = new DisplayMetrics();

getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);

}

/**

* 初始化gridview

*/

@SuppressLint("WrongViewCast")

private void initGridView(final JSONArray array) {

gridAdapter = new HomeMainGridAdapter(getActivity(), array, null);

gridView = (GridView) findViewById(R.id.gview);

horizontalScrollView = (HorizontalScrollView) findViewById(R.id.scrollView);

horizontalScrollView.setHorizontalScrollBarEnabled(false);// 隐藏滚动条

getScreenDen();

setValue();

gridView.setSelector(new ColorDrawable(Color.TRANSPARENT));

gridView.setAdapter(gridAdapter);

}

GridView 分页

string pagestring = string.Empty;

string linkurl = url;

int page = 0;

if (pagecount pagelist)

{

if (pagecount % pagelist != 0)

{

pagecount = (pagecount / pagelist)+1;

}

else

{

pagecount = pagecount / pagelist;

}

}

else

{

pagecount = 1;

}

if (pageindex == 0)

pageindex = 1;

//显示内容

if (pageindex 1)

{

pagestring = "lia href=\"" + linkurl + "?page=1" + urls + "\"首页/a/lilia href=\"" + linkurl + "?page=" + (pageindex - 1).ToString() + urls + "\"上页/a/li";

}

if (pagecount 1)

{

page = pagesize / 2;

if (pagecount page)//总数大于标准数

{

if (pagecount pagesize)

{

if (pageindex page)

{

//123456789011

if ((pageindex + page + 1) = pagecount)

for (int i = pageindex - (page - 1); i pageindex + page + 1; i++)

{

if (i == pageindex)

{

pagestring = pagestring + "li class=\"curpage\"" + i.ToString() + "/li";

}

else

{

pagestring = pagestring + "lia href=\"" + linkurl + "?page=" + i.ToString() + urls + "\"" + i.ToString() + "/a/li";

}

}

else

{

for (int i = pagecount - (pagesize+1); i pagecount + 1; i++)

{

if (i == pageindex)

{

pagestring = pagestring + "li class=\"curpage\"" + i.ToString() + "/li";

}

else

{

pagestring = pagestring + "lia href=\"" + linkurl + "?page=" + i.ToString() + urls + "\"" + i.ToString() + "/a/li";

}

}

}

}

else

{

for (int i = 1; i pagesize + 1; i++)

{

if (i == pageindex)

{

pagestring = pagestring + "li class=\"curpage\"" + i.ToString() + "/li";

}

else

{

pagestring = pagestring + "lia href=\"" + linkurl + "?page=" + i.ToString() + urls + "\"" + i.ToString() + "/a/li";

}

}

}

}

else

{

for (int i = 1; i pagecount + 1; i++)

{

if (i == pageindex)

{

pagestring = pagestring + "li class=\"curpage\"" + i.ToString() + "/li";

}

else

{

pagestring = pagestring + "lia href=\"" + linkurl + "?page=" + i.ToString() + urls + "\"" + i.ToString() + "/a/li";

}

}

}

}

else

{

for (int i = 1; i pagecount + 1; i++)

{

if (i == pageindex)

{

pagestring = pagestring + "li class=\"curpage\"" + i.ToString() + "/li";

}

else

{

pagestring = pagestring + "lia href=\"" + linkurl + "?page=" + i.ToString() + urls + "\"" + i.ToString() + "/a/li";

}

}

}

if (pageindex pagecount)

{

pagestring = pagestring + "lia href=\"" + linkurl + "?page=" + (pageindex + 1).ToString() + urls + "\"下页/a/lilia href=\"" + linkurl + "?page=" +pagecount.ToString()+ urls + "\"尾页/a/li";

}

}

return pagestring;

如何调整Gridview的分页显示位置

1、如果你想让所有的数据显示在一页里,而不启用分页可以设置AllowPaging=false 。 2、如果你想用自己设计的分页样式,而不显示gv预定的分页样式可以设置Gridview的 “pagersettings”属性里的 visible=false ,并且AllowPaging=true。这样你就可以通过更改Gridview.pageIndex属性值来改变分页。

GridView里的分页功能

你在绑定数据源之前,加个判断,判断数据源是否为空,不为空才绑定。

EmptyDataTemplate

div style="width: 100%"

暂时没有您要查找的数据!

/div

/EmptyDataTemplate或者在asp:GridView/asp:GridView标签之间加上上面那句话试试。

(责任编辑:IT教学网)

更多

推荐Illustrator教程文章