Remembering ListView page index and restoring it.
I am using ListView with DataPager to get a paging feature of my list.
I want to redirect my page when I click on an entry in the list view, show some detail information.
When I am done, I want to go back and view the exact same list of information.
That is, remembering the page index.
我是用DataPager幫我的ListView做分頁功能.我想要在使用者點選列表上某一條目後,
轉跳到別的頁面,顯示一些詳細資訊後,完成後回到剛才的列表頁面,要能看到剛才的那一個分頁.
就是說,要記住之前的頁碼.
Inside your ItemCommand handler method, use the following code snippet to find the correct startRowIndexStore this index whatever you want, I store it by using GET method.
在你的ItemCommand處理程序裡面,用下面的程式片段去找出正確的startRowIndex
//index of the clicked item within the whole list
int l_dataIndex = ((ListViewDataItem)e.Item).DataItemIndex;
//minus the index of the item in that page = startRowIndex
int l_startRowIndex = l_dataIndex - ((ListViewDataItem)e.Item).DisplayIndex;
把索引值存在你喜歡的地方,我把它儲存在GET方法裡
Why do I call the above correct startRowIndex and not using the DataPager.startRowIndex?
Because we are going to use DataPager.SetPageProperties() in Page_Load() to restore the page we previously looking at.
為甚麼我會說上面的是正確的startRowIndex還有不去用DataPager.startRowIndex呢?
因為我們將會在Page_Load()裡用DataPager.SetPageProperties()去顯示之前我們在看的分頁
dataPager.SetPageProperties(l_startRowIndex, dpg_dataPager.MaximumRows, true);
This will bring you back to the page as we expect. But after this call.
The startRowIndex won’t update now even though you click next/previous to change your page.
That is why I said this is not the correct startRowIndex. You can try this youself ^^.
這個調用會把你帶到之前的分頁,正如我們預期.但在這個調用後,
startRowIndex就會停止更新,就算你點選上一頁/下一頁也不會改變.
這就是為甚麼我說上面的才是正確的startRowIndex.你可以自己試一試 ^^.
It turns out that I have done something stupid. The SetPageProperties() have to be inside IsPostBack to work correctly.
Result in something like this.
//in ItemCommand handler
url += "&startRowIndex=" + dataPager.startRowIndex;
//in Page_Load
if (!IsPostBack)
{
dataPager.SetPageProperties(startRowIndex, dataPager.MaximumRows, true);
}
June 16, 2009 , Tuesday - Posted by maxi326 | Programming | ASP.NET, C#, DataPager, ListView, page number | No Comments Yet
No comments yet.
-
The Host
關於麥克斯
文章分類
- 科技與人生 (21)
- Linux (8)
- Eletronic (1)
- 台灣情 (3)
- 學習程式之道 (132)
- Computer Science Knowledge (6)
- Misc (3)
- Programming (77)
- Project (4)
- IrrTetris (1)
- ZidduDownloader (3)
- Project (4)
- Server (14)
- Tools (4)
- Web (27)
- Image (1)
- 科技與人生 (21)
-
Top Posts
Subscribe My Blog
-
Recent Comments
Tags
.Net AJAX ASP ASP.NET branch C# chart CSS Driver feisty fawn FF Google Map hack hotkey hover html Icefaces IE irrlicht java JavaScript JBoss JIRA Junit Linux ListView mysql Netbeans Open Xml Portlet ReportViewer scim spreadsheetML SQL server SQL server 2008 Express svn template Tomcat tomcat 6 transparency ubuntu User Control UTF-8 website z-indexCategory Cloud
其他功能
封存文章
-
Blog Stats
- 36,360 人路過
-
Spam Blocked
Scott Gu
Rick Strahl
MS MVP DBA
DotBlogs
暗黑執行緒
TheWillWillWeb
猴子靈藥
Weithenn
MS MVP 馬小靈
Eddie
{|ihower.idv.tw| blog }
網絡暴民 Jacky’s Blog
Peace Palace – 技術、評論、生活
百分百無聊人生- An error has occurred; the feed is probably down. Try again later.