gridview+objectdatasource+aspnetpager整合實例
前臺代碼:
<asp:GridView ID="viewIShow" runat="server" DataSourceID="ObjectDataSource1"
AllowPaging="True" AutoGenerateColumns="False"
OnRowCommand="viewIShow_RowCommand" PageSize="2"
OnPageIndexChanging="viewIShow_PageIndexChanging"
OnDataBound="viewIShow_DataBound">
<Columns>
<asp:BoundField DataField="title" HeaderText="名稱" />
<asp:BoundField DataField="clicknum" HeaderText="播放次數(shù)" />
<asp:BoundField DataField="addtime" HeaderText="更新日期" />
<asp:TemplateField HeaderText="操作">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="up" CommandArgument='<%#Eval("id") %>'>晉級</asp:LinkButton><asp:LinkButton
ID="LinkButton2" runat="server" CommandName="down" CommandArgument='<%#Eval("id") %>'>降級</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerTemplate>
<table border="0" cellpadding="0" cellspacing="1" style="width: 100%; height: 100%;">
<tr style="height: 28px; padding-left: 20px;">
<td class="pages">
<webdiyer:AspNetPager ID="myPage" runat="server"
OnPageChanged="myPage_PageChanged" ></webdiyer:AspNetPager>
</td>
</tr>
</table>
</PagerTemplate>
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
DataObjectTypeName="AUDIOSYSTEM.Model.ishow" DeleteMethod="Delete"
InsertMethod="Add" SelectMethod="GetList" TypeName="AUDIOSYSTEM.BLL.ishow"
UpdateMethod="Update" OnSelected="ObjectDataSource1_Selected">
<SelectParameters>
<asp:Parameter Name="type" Type="String" DefaultValue="week" />
<asp:ControlParameter ControlID="txtStartTime"
DefaultValue="2000/01/01 00:00:00" Name="start"
PropertyName="Text" Type="DateTime" />
<asp:ControlParameter ControlID="txtEndTime" Name="end" PropertyName="Text"
Type="DateTime" DefaultValue="2500/01/01 00:00:00" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="videoId" Type="Int32" />
<asp:Parameter Name="type" Type="String" DefaultValue="week" />
</DeleteParameters>
</asp:ObjectDataSource>
后臺代碼:
protected void myPage_PageChanged(object sender, EventArgs e)
{
GridViewRow pagerRow = viewIShow.BottomPagerRow;
AspNetPager myPage = (AspNetPager)pagerRow.Cells[0].FindControl("myPage");
viewIShow.PageIndex = myPage.CurrentPageIndex - 1;
}
protected void viewIShow_DataBound(object sender, EventArgs e)
{
GridViewRow pagerRow = viewIShow.BottomPagerRow;
AspNetPager myPage = (AspNetPager)pagerRow.Cells[0].FindControl("myPage");
GridView view = (GridView)sender;
myPage.PageSize = view.PageSize;
myPage.CurrentPageIndex = view.PageIndex +1; //GridView分頁索引是從0開始,AspNetPager是從1開始的
}
protected void ObjectDataSource1_Selected(object sender, ObjectDataSourceStatusEventArgs e)
{
DataSet ds = (DataSet)e.ReturnValue; //ObjectDataSource查詢方法返回什么類型就轉(zhuǎn)成什么類型
GridViewRow pagerRow = viewIShow.BottomPagerRow;
AspNetPager myPage = (AspNetPager)pagerRow.Cells[0].FindControl("myPage");
if (ds == null)
{
myPage.RecordCount = 0;
}
else
{
myPage.RecordCount = ds.Tables[0].Rows.Count;
}
}
- asp.net 使用ObjectDataSource控件在ASP.NET中實現(xiàn)Ajax真分頁
- 動態(tài)指定任意類型的ObjectDataSource對象的查詢參數(shù)
- ASP.NET中 ObjectDataSource控件的DataObjectTypeName屬性
- 在ASP.NET 2.0中操作數(shù)據(jù)之一:創(chuàng)建一個數(shù)據(jù)訪問層
- 在ASP.NET 2.0中操作數(shù)據(jù)之二:創(chuàng)建一個業(yè)務(wù)邏輯層
- 在ASP.NET 2.0中操作數(shù)據(jù)之三:創(chuàng)建母版頁和站點導(dǎo)航
- 在ASP.NET 2.0中操作數(shù)據(jù)之四:使用ObjectDataSource展現(xiàn)數(shù)據(jù)
- 在ASP.NET 2.0中操作數(shù)據(jù)之五:聲明參數(shù)
- 在ASP.NET 2.0中操作數(shù)據(jù)之六:編程設(shè)置ObjectDataSource的參數(shù)值
相關(guān)文章
DataList中TextBox onfocus調(diào)用后臺void靜態(tài)方法及獲取相應(yīng)行數(shù)
DataList中我放了一個TextBox 現(xiàn)在的問題是當(dāng)我光標(biāo)放到TextBox上的時候。如果讓onfocus調(diào)用后臺某一個void靜態(tài)方法并且在靜態(tài)方法里邊獲取光標(biāo)相應(yīng)的DataList的相應(yīng)行數(shù),本文介紹如何實現(xiàn),感興趣的朋友可以了解下2013-01-01asp.net core服務(wù)限制堆內(nèi)存大小的操作方法
asp.net core是微軟旗下支持跨平臺的開發(fā)框架,與springboot思想類似,支持ioc等,可以快速的開發(fā)web api等項目,這篇文章主要介紹了asp.net core服務(wù)限制堆內(nèi)存大小,需要的朋友可以參考下2022-09-09ASP.NET數(shù)據(jù)綁定GridView控件使用技巧
這篇文章主要為大家詳細(xì)介紹了ASP.NET數(shù)據(jù)綁定GridView控件使用技巧,感興趣的小伙伴們可以參考一下2016-03-03Asp.net靜態(tài)方法之Grid轉(zhuǎn)DataTable方法實現(xiàn)步驟
GridView綁定DataTable后,如何獲取GridView綁定后顯示的值,在項目需求的背景下寫了一個靜態(tài)方法,經(jīng)過在項目中的使用,bug的修復(fù),較為穩(wěn)定2013-04-04擴(kuò)展了Repeater控件的EmptyDataTemplate模板功能
Repeater控件是一個數(shù)據(jù)顯示控件,該控件允許通過為列表中顯示的每一項重復(fù)使用指定的模板來自定義布局2013-01-01微信公眾平臺開發(fā)之獲得ACCESSTOKEN .Net代碼解析
這篇文章主要為大家詳細(xì)解析了微信公眾平臺開發(fā)之獲得ACCESSTOKEN .Net代碼,感興趣的小伙伴們可以參考一下2016-06-06asp.net(C#)把漢字轉(zhuǎn)化成全拼音函數(shù)(全拼)
asp.net(C#)把漢字轉(zhuǎn)化成全拼音函數(shù)的代碼,需要的朋友可以參考下。2009-12-12