一、首先下载一个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="添加品牌" onclick="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 { } } #endregion protected void DgBM_ItemCommand(object source, DataGridCommandEventArgs e) { } protected void DgBM_ItemDataBound(object sender, DataGridItemEventArgs e) { } protected void btnAdd_Click(object sender, EventArgs e) { }