ASP.NET使用ajax實現(xiàn)分頁局部刷新頁面功能
listview列表實現(xiàn)分頁是非常容易的。ListView分頁是非常簡單的,加上一個DataPager控件,把ListView的ID賦予就可以了。最開始我就是這么寫的。(網(wǎng)上有人說這樣是偽分頁?)
<asp:ListView ID="newBlogItems" runat="server" DataSourceID="AccessDataSource1" ViewStateMode="Disabled"> <ItemTemplate> <li class="newBlogItem"> ..... </li> </ItemTemplate> </asp:ListView> <asp:DataPager ID="DataPager1" runat="server" PageSize="15" PagedControlID="newBlogItems" ViewStateMode="Disabled"> <Fields> <asp:NextPreviousPagerField ButtonType="Link" ShowFirstPageButton="True" ShowNextPageButton="False" ShowPreviousPageButton="False" /> <asp:NumericPagerField /> <asp:NextPreviousPagerField ButtonType="Link" ShowLastPageButton="True" ShowNextPageButton="False" ShowPreviousPageButton="False" /> </Fields> </asp:DataPager>
然而這樣寫完,點擊分頁的效果是刷新整個頁面,刷新后頁面跳來跳去當(dāng)然是不友好的,所以要局部更新頁面,最開始就想到了jquery插件,于是在網(wǎng)上下載了JPAGES這個插件,擺弄了半天也沒弄成,也不知道哪里有錯誤。。。于是棄坑了,還是ajax吧!。
使用ajax方法就很簡單拉,把大象裝冰箱總共分三步。
1.引入ajax控件ScriptManager,放在form里。
2.引入ajax控件UpdatePanel。
3.編輯UpdatePanel內(nèi)容。
主要是兩個,ContentTemplate和Trigger。先把listView扔ContentTemplate里面。然后在Trigger里面加入asp:AsyncPostBackTrigger,將ID指向之前的分頁控件DataPager控件,這樣就可以了。代碼如下:
<asp:UpdatePanel runat="server"> <ContentTemplate> <%--數(shù)據(jù)源--%> <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="C:\storage\users.accdb" SelectCommand="SELECT [userName], [blogTitle], [blogTime], [blogUrl],[statis] FROM [blog] ORDER BY [blogTime] DESC"></asp:AccessDataSource> <asp:ListView ID="newBlogItems" runat="server" DataSourceID="AccessDataSource1" ViewStateMode="Disabled"> <ItemTemplate> <li class="newBlogItem"> 此處略去1000字 </li> </ItemTemplate> </asp:ListView> <asp:DataPager ID="DataPager1" runat="server" PageSize="15" PagedControlID="newBlogItems" ViewStateMode="Disabled"> <Fields> <asp:NextPreviousPagerField ButtonType="Link" ShowFirstPageButton="True" ShowNextPageButton="False" ShowPreviousPageButton="False" /> <asp:NumericPagerField /> <asp:NextPreviousPagerField ButtonType="Link" ShowLastPageButton="True" ShowNextPageButton="False" ShowPreviousPageButton="False" /> </Fields> </asp:DataPager> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="DataPager1"/> </Triggers> </asp:UpdatePanel>
以上所述是小編給大家介紹的ASP.NET使用ajax實現(xiàn)分頁局部刷新頁面功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
FreeTextBox(版本3.1.6)在ASP.Net 2.0中使用方法
在ASP.Net 2.0中使用,只需要2個文件:FreeTextBox.DLL和ftb.imagegallery.aspx2009-11-11visual studio 2019使用net core3.0創(chuàng)建winform無法使用窗體設(shè)計器
這篇文章主要介紹了visual studio 2019使用net core3.0創(chuàng)建winform無法使用窗體設(shè)計器,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-03-03關(guān)于ASP.NET頁面打印技術(shù)的常用方法總結(jié)
B/S結(jié)構(gòu)導(dǎo)致了Web應(yīng)用程序中打印的特殊性;程序運行在瀏覽器中,打印機(jī)在本地,而文件確可能在服務(wù)器上,導(dǎo)致了打印控制不是很靈活,接下來介紹幾種常見的打印技術(shù),感興趣的朋友可以了解下2013-01-01asp.net下Response.ContentType類型匯總
asp.net下Response.ContentType類型匯總...2007-04-04ASP.NET也像WinForm程序一樣運行的實現(xiàn)方法
我們今天要談到的是讓ASP.NET的程序也像WinForm一樣的運行,這樣就不需要安裝IIS或者Visual Studio這樣的特定環(huán)境了2012-01-01基于.Net?Core認(rèn)證授權(quán)方案之JwtBearer認(rèn)證
這篇文章介紹了基于.Net?Core認(rèn)證授權(quán)方案之JwtBearer認(rèn)證,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-06-06