Repeater 数据更新不了
点击前点击后
就是RPT里面没有变化 记录数都变化了!
程序代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WzJyw.manager.WebForm2" %> <%@ Import Namespace = "DataCommon" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www."> <html xmlns="http://www."> <head id="Head1" runat="server"> <title>无标题页</title> <link rel="stylesheet" type="text/css" href="skin/css/main.css"> <style type="text/css"> .style1 { width: 15%; height: 24px; } .style3 { width: 5%; height: 24px; } .style4 { width: 10%; height: 24px; } </style> </head> <body> <form id="form1" runat="server"> <script language="jscript" src="../My97DatePicker/WdatePicker.js"></script> <div style="text-align: center"> <table width="98%" border="0" cellpadding="1" cellspacing="1" align="center" style="margin-top: 8px"> <tr> <td> <strong>用户名:</strong><asp:TextBox ID="txtYongHu" runat="server"></asp:TextBox> <strong>类型:</strong><asp:DropDownList ID="drplstType" runat="server"> </asp:DropDownList> <strong>注册时间:</strong><asp:TextBox ID="txtZhuCeShiJian" runat="server" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',alwaysUseStartDate:true})"></asp:TextBox> <asp:Button ID="btnSouSuo" runat="server" Text="搜索" onclick="btnSouSuo_Click" /> </td> </tr> <tr> <td> <table bgcolor="#D1DDAA" width="100%" border="0" cellpadding="1" cellspacing="1" align="center"> <thead> <tr bgcolor="#E7E7E7"> <td height="24" colspan="5" background="skin/images/tbg.gif"> 会员列表 </td> </tr> <tr bgcolor="#FAFAF1"> <th class="style1"> 用户名 </th> <th class="style1"> 密码 </th> <th class="style3"> 类型 </th> <th class="style1"> 注册时间 </th> <th class="style4"> 操作 </th> </tr> </thead> <tbody> <asp:Repeater ID="Repeater1" runat="server"> <ItemTemplate> <tr align='center' bgcolor="#FFFFFF" onmousemove="javascript:this.bgColor='#FCFDEE';" onmouseout="javascript:this.bgColor='#FFFFFF';"> <td class="style1"> <a href="DetailsManager.aspx?userid=<%#DataCommon.Users.GetUserid(Eval("YongHu").ToString())%>"> <%#Eval("YongHu")%></a> </td> <td class="style1"> <%#Eval("Passwod")%> </td> <td class="style3"> <%#Users.Gettype(int.Parse(Eval("Type").ToString()))%> </td> <td class="style1"> <%#Eval("RegistDateTime")%> </td> <td class="style4"> <a href="UserManager.aspx?id=<%#Eval("Id")%>">修改</a> <asp:LinkButton ID="LinkButton1" runat="server" OnClientClick="return confirm('您确定删除吗')" CommandArgument='<%#Eval("Id")%>' OnClick="LinkButton1_Click">删除</asp:LinkButton> </td> </tr> </ItemTemplate> </asp:Repeater> </tbody> <tfoot> <tr> <td height="22" colspan="5" bgcolor="#FFFFFF"> <webdiyer:AspNetPager ID="AspNetPager1" runat="server" Width="100%" NumericButtonCount="6" NumericButtonTextFormatString="[{0}]" CustomInfoHTML="第 <font color='red'><b>%CurrentPageIndex%</b></font> 页 共 %PageCount% 页 显示 %StartRecordIndex%-%EndRecordIndex% 条" ShowCustomInfoSection="left" FirstPageText="首页" LastPageText="末页" NextPageText="下页" PrevPageText="上页" Font-Names="Arial" AlwaysShow="true" ShowInputBox="Always" SubmitButtonText="跳转" SubmitButtonStyle="botton" OnPageChanged="AspNetPager1_PageChanged" PageSize="4" CustomInfoTextAlign="Center" HorizontalAlign="Center" Height="20px"> </webdiyer:AspNetPager> </td> </tr> </tfoot> </table> </td> </tr> </table> </div> </form> </body> </html>
程序代码:
using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Data.SqlClient; using DataCommon; using Common; namespace WzJyw.manager { public partial class WebForm2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { DaoRu(); } } protected void DaoRu() { TypeBind(); SqlConnection con = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction); SqlCommand cmd = new SqlCommand("Users_select2", con); = CommandType.StoredProcedure; cmd.Parameters.Add("pagesize", SqlDbType.Int, 1); cmd.Parameters["pagesize"].Value = 1; cmd.Parameters.Add("pageindex", SqlDbType.Int, 1); cmd.Parameters["pageindex"].Value = 1; cmd.Parameters.Add("docount", SqlDbType.Bit); cmd.Parameters["docount"].Value = true; cmd.Parameters.Add("YongHu", SqlDbType.VarChar, 13); cmd.Parameters["YongHu"].Value = txtYongHu.Text.Trim(); cmd.Parameters.Add("Type", SqlDbType.Int, 1); cmd.Parameters["Type"].Value = int.Parse(drplstType.SelectedValue); con.Open(); AspNetPager1.RecordCount = (int)cmd.ExecuteScalar(); SetDataBind(); } protected void TypeBind() { drplstType.Items.Clear(); ListItem lst = new ListItem("全部", "0"); drplstType.Items.Add(lst); Array stateArray = Enum.GetValues(typeof(Users.type)); foreach (int i in stateArray) { drplstType.Items.Add(new ListItem(Users.Gettype(i), i.ToString())); } } private void SetDataBind() { SqlConnection con = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction); SqlCommand cmd = new SqlCommand("Users_select2", con); = CommandType.StoredProcedure; cmd.Parameters.Add("pagesize", SqlDbType.Int,1); cmd.Parameters["pagesize"].Value = AspNetPager1.PageSize; cmd.Parameters.Add("pageindex", SqlDbType.Int,1); cmd.Parameters["pageindex"].Value = AspNetPager1.CurrentPageIndex; cmd.Parameters.Add("docount", SqlDbType.Bit); cmd.Parameters["docount"].Value = false; cmd.Parameters.Add("YongHu", SqlDbType.VarChar, 13); cmd.Parameters["YongHu"].Value = txtYongHu.Text.Trim(); cmd.Parameters.Add("Type", SqlDbType.Int, 1); cmd.Parameters["Type"].Value = int.Parse(drplstType.SelectedValue); con.Open(); Repeater1.DataSource = cmd.ExecuteReader(); Repeater1.DataBind(); } protected void LinkButton1_Click(object sender, EventArgs e) { try { LinkButton lb = (LinkButton)sender; int id = 0; int.TryParse(, out id); int i = Users.Delete(id); if (i > 0) { UserMatter.Add(id, (int)UserMatter.MatterType.ShanChu, "删除用户" + Users.GetField(id, "YongHu")); MBox.RefUrl(2); } else { Response.Redirect("Error.aspx"); } } catch { Response.Redirect("Error.aspx"); } } protected void AspNetPager1_PageChanged(object sender, EventArgs e ) { SetDataBind(); } protected void btnSouSuo_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction); SqlCommand cmd = new SqlCommand("Users_select2", con); = CommandType.StoredProcedure; cmd.Parameters.Add("pagesize", SqlDbType.Int, 1); cmd.Parameters["pagesize"].Value = 1; cmd.Parameters.Add("pageindex", SqlDbType.Int, 1); cmd.Parameters["pageindex"].Value = 1; cmd.Parameters.Add("docount", SqlDbType.Bit); cmd.Parameters["docount"].Value = true; cmd.Parameters.Add("YongHu", SqlDbType.VarChar, 13); cmd.Parameters["YongHu"].Value = txtYongHu.Text.Trim(); cmd.Parameters.Add("Type", SqlDbType.Int, 1); cmd.Parameters["Type"].Value = int.Parse(drplstType.SelectedValue); con.Open(); AspNetPager1.RecordCount = (int)cmd.ExecuteScalar(); SetDataBind(); } } }
程序代码:
CREATE procedure Users_select2 (@YongHu VarChar(13), @Type int, @pagesize int, @pageindex int, @docount bit) as set nocount on if(@docount=1) if(@yonghu='') if(@type=0) select count(*) from Users else select count(*) from Users where type= @type else if(@type=0) select count(*) from Users where yonghu like @yonghu else select count(*) from Users where yonghu like @yonghu and type=@type else begin declare @indextable table(id int identity(1,1),nid int) declare @PageLowerBound int declare @PageUpperBound int set @PageLowerBound=(@pageindex-1)*@pagesize set @PageUpperBound=@PageLowerBound+@pagesize set rowcount @PageUpperBound insert into @indextable(nid) select ID from Users select * from Users O,@indextable t where O.ID=t.nid and t.id between @PageLowerBound+1 and @PageUpperBound order by t.id end set nocount off GO