Repeater 的分页问题
<asp:Panel ID="Panel1" runat="server" Width="900px" ><asp:Label ID="Label1" runat="server" Text="开始时间" style="font-size:12px;padding: 0px 5px 0px 0px;"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Label ID="Label3" runat="server" Text="(格式2011-01-01)" style="font-size:12px;color:Red;padding: 0px 25px 0px 1px;"></asp:Label>
<asp:Label ID="Label2" runat="server" Text="结束时间" style="font-size:12px;padding: 0px 5px 0px 0px;"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Label ID="Label4" runat="server" Text="(格式2011-01-01)" style="font-size:12px;color:Red;padding: 0px 25px 0px 1px;"></asp:Label>
<asp:Button ID="Button1" runat="server" Text="查询" Width="73px"
style="font-size:12px;" Height="27px" onclick="Button1_Click"/>
</asp:Panel>
<br />
<asp:Repeater ID="Repeater1" runat="server" onitemdatabound="RowBound">
<HeaderTemplate>
<br />
<table border="1" cellpadding="0" align="center" width="950px" cellspacing="0" style="border-collapse:collapse;border:solid 1px #B9D3EE;background-color:White;">
<tr style="background-color:#CAE1FF;padding:0px 0px;Height:35px;font-size:12px;color:#3C3C3C;">
<td id="Td1">编号</td>
<td>用户名</td>
<td>变动金额</td>
<td>操作时间</td>
<td>操作人</td>
<td>变动后余额</td>
<td>变动详细</td></tr></HeaderTemplate>
<ItemTemplate><tr><td style=" width:100px"><%#Eval("id") %></td><td><%#Eval("user")%></td>
<td><%#Eval("money") %></td>
<td><%#Eval("time") %></td>
<td><%#Eval("operation") %></td>
<td><%#Eval("balance") %></td>
<td style=" width:300px"><%#Eval("notes") %></td></tr></ItemTemplate>
<FooterTemplate><tr>
<td colspan="7">
<asp:HyperLink ID="first" runat="server" Text="首页"></asp:HyperLink>
<asp:HyperLink ID="pre" runat="server" Text="上一页"></asp:HyperLink>
<asp:PlaceHolder ID="pages" runat="server"></asp:PlaceHolder>
<asp:HyperLink ID="next" runat="server" Text="下一页"></asp:HyperLink>
<asp:HyperLink ID="last" runat="server" Text="末页"></asp:HyperLink>
<asp:HyperLink ID="HyperLink1" runat="server" Text="当前第x页,共x页"></asp:HyperLink>
</td></tr></table>
</FooterTemplate>
</asp:Repeater>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.TextBox1.Text = DateTime.Now.AddDays(-1).ToString().Substring(0, 10);
this.TextBox2.Text = DateTime.Now.ToString().Substring(0, 10);
pagedata2 = new PagedDataSource();
DataTable dt2 = query.GetDateSetBySql("select * from Funds where time between '" + TextBox1.Text.Trim() + "' and '" + TextBox2.Text.Trim() + "' order by id").Tables[0];
pagedata2.DataSource = dt2.DefaultView;
pagedata2.AllowPaging = true;
pagedata2.PageSize = pagesize;
totalpage = pagedata2.PageCount;
pagedata2.CurrentPageIndex = this.GetCurrentPage() - 1;
this.Repeater1.DataSource = pagedata2;
this.Repeater1.DataBind();
}
}
protected int GetCurrentPage()
{
string page = Request.QueryString["page"];
if (page != null)
{
try
{
this.currentPage = Convert.ToInt32(page);
if (this.currentPage < 1)
{
this.currentPage = 1;
}
if (this.currentPage > this.totalpage)
{
this.currentPage = this.totalpage;
}
}
catch
{
this.currentPage = 1;
}
}
else
{
this.currentPage = 1;
}
return this.currentPage;
}
protected void RowBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Footer)
{
HyperLink first = (HyperLink)e.Item.FindControl("first");
HyperLink pre = (HyperLink)e.Item.FindControl("pre");
HyperLink next = (HyperLink)e.Item.FindControl("next");
HyperLink last = (HyperLink)e.Item.FindControl("last");
HyperLink HyperLink1 = (HyperLink)e.Item.FindControl("HyperLink1");
HyperLink1.Text = "第" + (pagedata2.CurrentPageIndex + 1) + "页、共" + (pagedata2.PageCount.ToString()) + "页";
first.NavigateUrl = "?page=1";
last.NavigateUrl = "?page=" + this.totalpage.ToString();
pre.NavigateUrl = "?page=" + (this.currentPage - 1).ToString();
next.NavigateUrl = "?page=" + (this.currentPage + 1).ToString();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
pagedata2 = null;
Repeater1 = null;
PagedDataSource pagedata = new PagedDataSource();
DataTable dt2 = query.GetDateSetBySql("select * from Funds where time between '" + TextBox1.Text.Trim() + "' and '" + TextBox2.Text.Trim() + "' order by id").Tables[0];
pagedata.DataSource = dt2.DefaultView;
pagedata.AllowPaging = true;
pagedata.PageSize = pagesize;
totalpage = pagedata.PageCount;
pagedata.CurrentPageIndex = this.GetCurrentPage() - 1;
this.Repeater1.DataSource = pagedata;
this.Repeater1.DataBind();
}
catch (Exception es)
{
Response.Write(es.ToString());
}
}
在第一次加载页面 分页和显示都是正常的,再点击按钮按时间再次查询的时候就不行了,Repeater里面好像还是第一次加载的东西,点查询也没有任何的效果,并且有时还会报错,【this.Repeater1.DataSource = pagedata;
this.Repeater1.DataBind();】 报“未将对象引用设置到对象的实例” 我是个初学者,麻烦各位大侠给看下哈,感激不尽 --------------------编程问答-------------------- 就是刚进页面比如说是查询28-29号的没有问题 我再次选择26-27好的就不行,结果还是28-29号的数据
--------------------编程问答-------------------- 就用ASPNETPAGE控件 --------------------编程问答-------------------- 去掉PageLoad里的if (!IsPostBack)。
--------------------编程问答-------------------- 去掉if (!IsPostBack)
补充:.NET技术 , C#