c#一个分页控件的例子
生活随笔
收集整理的這篇文章主要介紹了
c#一个分页控件的例子
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、首先下載一個dll,地址:http://pan.baidu.com/share/link?shareid=1628211605&uk=1342867987
二、添加到項目中
三、添加引用
四、前臺頁面寫法如下:
?
<head runat="server"><title></title> </head> <body><form id="form1" runat="server"><div><h3 style="color:Green;">品牌列表</h3><div style="text-align:right;margin-bottom:5px;margin-right:35px;"><asp:Button ID="btnAdd" runat="server" Text="添加品牌" οnclick="btnAdd_Click" /></div><asp:DataGrid ID="DgBM" runat="server" HorizontalAlign="Center" Width="100%" AllowSorting="True"AutoGenerateColumns="False" BorderStyle="None" GridLines="None" PageSize="2"DataKeyField="id" OnItemCommand="DgBM_ItemCommand" OnItemDataBound="DgBM_ItemDataBound"><AlternatingItemStyle ></AlternatingItemStyle><ItemStyle ></ItemStyle><HeaderStyle ></HeaderStyle><Columns><asp:BoundColumn DataField="BTitle" HeaderText="標題"></asp:BoundColumn><asp:BoundColumn DataField="Gtype" HeaderText="類型"></asp:BoundColumn><asp:BoundColumn DataField="createTime" HeaderText="創建時間"></asp:BoundColumn><asp:BoundColumn DataField="Description" HeaderText="描述"></asp:BoundColumn><asp:TemplateColumn HeaderText="編輯" HeaderStyle-Width="60px"><ItemTemplate><asp:ImageButton ID="Editimg" runat="server" CommandName="edit"ImageUrl="~/Images/work/edit.gif" AlternateText="編輯"></asp:ImageButton></ItemTemplate><EditItemTemplate><asp:ImageButton ID="Saveimg" runat="server" CommandName="save"AlternateText="保存"></asp:ImageButton><asp:ImageButton ID="Closeimg" runat="server" CommandName="close"AlternateText="取消"></asp:ImageButton></EditItemTemplate></asp:TemplateColumn><asp:TemplateColumn HeaderText="刪除" HeaderStyle-Width="60px"><ItemTemplate><asp:ImageButton ID="Delimg" runat="server" CssClass="btn_op" CommandName="del" ImageUrl="~/images/work/del.gif"></asp:ImageButton></ItemTemplate></asp:TemplateColumn></Columns></asp:DataGrid><table cellspacing="0" cellpadding="0" width="95%"><tr><td><cc1:SqlPager ID="SqlPager1" runat="server" ControlToPaginate="DgBM" Height="30px"BorderWidth="0px" BackColor="#FFFFFF" PagerStyle="ImageButtonNumericPageItems"firstImg="../../images/work/first.gif" lastImg="../../images/work/last.gif" nextImg="../../images/work/next.gif"prevImg="../../images/work/previous.gif" Width="100%" /><br /></td></tr></table></div></form> </body> </html>?
后臺代碼如下:
protected void Page_Load(object sender, EventArgs e){if (!Page.IsPostBack){PageBind();}}#region 分頁綁定列表/// <summary>/// 綁定通知公告列表/// </summary>public void PageBind(){string connStr = ConfigurationManager.AppSettings["DataConn"].ToString();string strCmd = "SELECT id,BTitle,(SELECT BTitle FROM BrandType WHERE id=Brand.BTID ) AS Gtype,createTime,imgURL,Description,sort FROM Brand";try{// 清除緩存 SqlPager1.ClearCache();// 綁定數據.SqlPager1.ConnectionString = connStr;SqlPager1.SelectCommand = strCmd;SqlPager1.SortField = "sort ASC";SqlPager1.ItemsPerPage = 20;SqlPager1.DataBind();}catch { }}#endregionprotected void DgBM_ItemCommand(object source, DataGridCommandEventArgs e){}protected void DgBM_ItemDataBound(object sender, DataGridItemEventArgs e){}protected void btnAdd_Click(object sender, EventArgs e){}?
轉載于:https://www.cnblogs.com/honghong75042/p/3238649.html
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的c#一个分页控件的例子的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: POJ 1321 棋盘问题(DFS 状
- 下一篇: OpenGL-渲染管线的流程(有图有真相