ASP.NET使用ajax實(shí)現(xiàn)分頁(yè)局部刷新頁(yè)面功能
listview列表實(shí)現(xiàn)分頁(yè)是非常容易的。ListView分頁(yè)是非常簡(jiǎn)單的,加上一個(gè)DataPager控件,把ListView的ID賦予就可以了。最開(kāi)始我就是這么寫(xiě)的。(網(wǎng)上有人說(shuō)這樣是偽分頁(yè)?)
<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>
然而這樣寫(xiě)完,點(diǎn)擊分頁(yè)的效果是刷新整個(gè)頁(yè)面,刷新后頁(yè)面跳來(lái)跳去當(dāng)然是不友好的,所以要局部更新頁(yè)面,最開(kāi)始就想到了jquery插件,于是在網(wǎng)上下載了JPAGES這個(gè)插件,擺弄了半天也沒(méi)弄成,也不知道哪里有錯(cuò)誤。。。于是棄坑了,還是ajax吧!。
使用ajax方法就很簡(jiǎn)單拉,把大象裝冰箱總共分三步。
1.引入ajax控件ScriptManager,放在form里。
2.引入ajax控件UpdatePanel。
3.編輯UpdatePanel內(nèi)容。
主要是兩個(gè),ContentTemplate和Trigger。先把listView扔ContentTemplate里面。然后在Trigger里面加入asp:AsyncPostBackTrigger,將ID指向之前的分頁(yè)控件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實(shí)現(xiàn)分頁(yè)局部刷新頁(yè)面功能,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
- 使用ajax局部刷新gridview進(jìn)行數(shù)據(jù)綁定示例
- 利用ajax實(shí)現(xiàn)簡(jiǎn)單的注冊(cè)驗(yàn)證局部刷新實(shí)例
- ajax局部刷新一個(gè)div下jsp內(nèi)容的方法
- Ajax異步無(wú)刷新對(duì)局部數(shù)據(jù)更新
- 在Thinkphp中使用ajax實(shí)現(xiàn)無(wú)刷新分頁(yè)的方法
- Bootstrap Paginator分頁(yè)插件與ajax相結(jié)合實(shí)現(xiàn)動(dòng)態(tài)無(wú)刷新分頁(yè)效果
- ajax無(wú)刷新分頁(yè)的簡(jiǎn)單實(shí)現(xiàn)
相關(guān)文章
FreeTextBox(版本3.1.6)在ASP.Net 2.0中使用方法
在ASP.Net 2.0中使用,只需要2個(gè)文件:FreeTextBox.DLL和ftb.imagegallery.aspx2009-11-11
visual studio 2019使用net core3.0創(chuàng)建winform無(wú)法使用窗體設(shè)計(jì)器
這篇文章主要介紹了visual studio 2019使用net core3.0創(chuàng)建winform無(wú)法使用窗體設(shè)計(jì)器,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-03-03
關(guān)于ASP.NET頁(yè)面打印技術(shù)的常用方法總結(jié)
B/S結(jié)構(gòu)導(dǎo)致了Web應(yīng)用程序中打印的特殊性;程序運(yùn)行在瀏覽器中,打印機(jī)在本地,而文件確可能在服務(wù)器上,導(dǎo)致了打印控制不是很靈活,接下來(lái)介紹幾種常見(jiàn)的打印技術(shù),感興趣的朋友可以了解下2013-01-01
asp.net下Response.ContentType類型匯總
asp.net下Response.ContentType類型匯總...2007-04-04
ASP.NET也像WinForm程序一樣運(yùn)行的實(shí)現(xiàn)方法
我們今天要談到的是讓ASP.NET的程序也像WinForm一樣的運(yùn)行,這樣就不需要安裝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)證,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-06-06

