<asp:Panel ID="Panel1" runat="server" > <table class="imagetable"> <tr> <th>ID</th> <th>银行名称</th> <th>是否停用</th> <th>操作</th> </tr> <asp:Repeater ID="list" runat="server" OnItemCommand="list_ItemCommand"> <ItemTemplate> <tr> <td><%# Eval("id")%></td> <td><%# Eval("name")%></td> <td><asp:LinkButton ID="LinkButton1" runat="server" CommandArgument='<%#Eval("id") %>' CommandName="update"><%# Set_jinyong(Eval("id").ToString(),Eval("is_rec").ToString()) %></asp:LinkButton></td> <td> <%--<a href="#">添加下级地区</a>|--%> <a href="Bank_update.aspx?id=<%#Eval("id") %>">编辑</a> |<asp:LinkButton ID="LinkButton2" runat="server" CommandArgument='<%#Eval("id") %>' CommandName="dele" OnClientClick= "return confirm( '你确定要删除这条记录? '); ">删除</asp:LinkButton> </td> </tr> </ItemTemplate> </asp:Repeater> </table> <br /> <asp:Button ID="BtnUp" runat="server" onclick="BtnUp_Click" Text="上一页" /> <asp:Button ID="BtnDown" runat="server" onclick="BtnDown_Click" Text="下一页" /> 跳到第<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>页 <asp:Button ID="Button2" runat="server" Text="GO" OnClick="Button2_Click"/> 共<asp:Label ID="Num_Count" runat="server" Text="Label"></asp:Label>页----当前第<asp:Label ID="num" runat="server"></asp:Label>页 </asp:Panel>
以上是页面
下面是后台代码
protected void Page_Load(object sender, EventArgs e) { BasePage_Load(new object(), new EventArgs()); if (!IsPostBack) { num.Text = "1"; Data_Bind(); } } private void Data_Bind() { string sqlstr = " 1=1 "; if (TextBox1.Text.Trim() != "") { sqlstr += " and name like '%" + TextBox1.Text + "%'"; } DataSet ds = new DataSet(); ds = tb_bank.GetList(sqlstr); PagedDataSource pds = new PagedDataSource(); pds.DataSource = ds.Tables[0].DefaultView; pds.AllowPaging = true;//允许分页 pds.PageSize = 20;//单页显示项数 int i = ds.Tables[0].Rows.Count / pds.PageSize; if (i * pds.PageSize < ds.Tables[0].Rows.Count) { Num_Count.Text = (ds.Tables[0].Rows.Count / pds.PageSize + 1).ToString(); } else { Num_Count.Text = (ds.Tables[0].Rows.Count / pds.PageSize).ToString(); } int curpage = Convert.ToInt32(num.Text); this.BtnDown.Enabled = true; this.BtnUp.Enabled = true; pds.CurrentPageIndex = curpage - 1; if (curpage == 1) { this.BtnUp.Enabled = false; } if (curpage == pds.PageCount) { this.BtnDown.Enabled = false; } list.DataSource = pds; list.DataBind(); } public string Set_jinyong(string id, string is_rec) { DataSet ds = new DataSet(); ds = tb_bank.GetList("id=" + id + ""); if (is_rec == "1") { return "已停用"; } else { return "已启用"; } } protected void Button1_Click(object sender, EventArgs e) { Data_Bind(); } protected void BtnUp_Click(object sender, EventArgs e) { this.num.Text = Convert.ToString(Convert.ToInt32(num.Text) - 1); Data_Bind(); } protected void BtnDown_Click(object sender, EventArgs e) { this.num.Text = Convert.ToString(Convert.ToInt32(num.Text) + 1); Data_Bind(); } protected void Button2_Click(object sender, EventArgs e) { int result = -1; //result 定义为out 用来输出值 try { result = Convert.ToInt32(TextBox3.Text); if (int.Parse(Num_Count.Text) < int.Parse(TextBox3.Text) || int.Parse(TextBox3.Text) < 0) { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('请输入正确页码!')</script>"); return; } this.num.Text = TextBox3.Text; } catch { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('请输入整数!')</script>"); return; } Data_Bind(); }