简体   繁体   English

使用gridview asp.net c#外的按钮调用gridview分页

[英]invoke gridview paging using button outside the gridview asp.net c#

How can you invoke the paging of a gridview using button from the outside of the gridview? 您如何使用gridview外部的按钮调用gridview的页面调度?

I have searched it but unfortunately I can't find the right logic for it. 我已经搜索了它,但是不幸的是我找不到合适的逻辑。 I'm not talking about creating a button for preview and next function inside the pager template of the gridview, but outside, the gridview itself like a remote button. 我不是在谈论在gridview的寻呼机模板内部创建用于预览和下一个功能的按钮,而是在外部,gridview本身就像一个远程按钮。 Whenever I click either the preview or next button, the gridview will do the same. 每当我单击“预览”或“下一步”按钮时,gridview都会执行相同的操作。

Suppose you have the Button outside the Grid View. 假设您在网格视图外部有按钮。 You can do grid view paging as follows on the button click. 单击按钮后,可以按以下步骤进行网格视图分页。

Basically we need to set the pageindex of the grid view and rebind the data. 基本上,我们需要设置网格视图的pageindex并重新绑定数据。 You need to have the data stored in session/cache or get it afresh for the gridview. 您需要将数据存储在会话/缓存中,或者重新获取该数据以用于gridview。

protected void ButtonNext_Click(object sender, EventArgs e)
{
 ++gridview.PageIndex;  

 // if we have reached the last page, either set to first page. 
 // you could also do nothing.
 if (gridview.PageIndex >= gridview.PageCount)
 {
  gridview.PageIndex = 0;
 }

 gridview.DataSource = GetGridViewData(); // the data needs to be available.

 gridview.DataBind(); 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM