最近在编程人生上看到篇文章很有感触,觉得人生还是要多奋斗。今天给大家贡献点干货。
<divclass="page"id="ctrlRecordPage">
总<asp:LabelID="Zpage"runat="server"Text=""></asp:Label>页/
<asp:LabelID="Zcount"runat="server"Text=""></asp:Label>条
<asp:LinkButtonID="start_button"runat="server"onclick="start_button_Click">首页</asp:LinkButton>
<asp:LinkButtonID="up_button"runat="server"onclick="up_button_Click">上一页</asp:LinkButton>
<asp:LinkButtonID="down_button"runat="server"onclick="down_button_Click">下一页</asp:LinkButton>
<asp:LinkButton ID="end_button" runat="server" onclick="end_button_Click">末页</asp:LinkButton>
每页<asp:TextBoxID="Pagesize"runat="server"Text=""Width="30px"></asp:TextBox>条
当前<asp:DropDownListID="Pageing"runat="server"AutoPostBack="True"
onselectedindexchanged="Pageing_SelectedIndexChanged"></asp:DropDownList>页
</div>
privatevoidPageing_databird(intvalue)
{
Pageing.Items.Clear();
intzdatapage=Convert.ToInt32(Zpage.Text);
if(zdatapage>)
{
for(inti=;i<=zdatapage;i++)
{
Pageing.Items.Add(i.ToString());
}
}
else
{
Pageing.Items.Add("");
}
if(Pageing.Items.FindByValue(value.ToString())!=null)Pageing.SelectedValue=value.ToString();
if(zdatapage>)
{
Pageing.Enabled=true;
intdatapageing=Convert.ToInt32(Pageing.SelectedValue);
if(datapageing>)
{
start_button.Enabled=true;
up_button.Enabled=true;
}
else
{
start_button.Enabled=false;
up_button.Enabled=false;
}
if(datapageing<zdatapage)
{
down_button.Enabled=true;
end_button.Enabled=true;
}
else
{
down_button.Enabled=false;
end_button.Enabled=false;
}
}
else
{
start_button.Enabled=false;
up_button.Enabled=false;
down_button.Enabled=false;
end_button.Enabled=false;
Pageing.Enabled=false;
}
}
protectedvoidstart_button_Click(objectsender,EventArgse)
{
intdatapageing=;
if(Pageing.Items.FindByValue(datapageing.ToString())!=null)Pageing.SelectedValue=datapageing.ToString();
DataBird();
}
protectedvoidup_button_Click(objectsender,EventArgse)
{
intdatapageing=Convert.ToInt32(Pageing.SelectedValue);
if(datapageing>)datapageing--;
if(Pageing.Items.FindByValue(datapageing.ToString())!=null)Pageing.SelectedValue=datapageing.ToString();
DataBird();
}
protectedvoiddown_button_Click(objectsender,EventArgse)
{
intdatapageing=Convert.ToInt32(Pageing.SelectedValue);
intzdatapage=Convert.ToInt32(Zpage.Text);
if(datapageing<zdatapage)datapageing++;
if(Pageing.Items.FindByValue(datapageing.ToString())!=null)Pageing.SelectedValue=datapageing.ToString();
DataBird();
}
protectedvoidend_button_Click(objectsender,EventArgse)
{
intzdatapage=Convert.ToInt32(Zpage.Text);
if(Pageing.Items.FindByValue(zdatapage.ToString())!=null)Pageing.SelectedValue=zdatapage.ToString();
DataBird();
}
protectedvoidPageing_SelectedIndexChanged(objectsender,EventArgse)
{
DataBird();
}
protectedvoidDataBird()
{
dc.Setsql="select*fromadlistorderbycreatetimedesc";
DataTabledt=dc.GetDataTable();
PagedDataSourcepds=newPagedDataSource();
pds.DataSource=dt.DefaultView;
pds.AllowPaging=true;
intdatapagesize=;
if(Convert.ToInt32(Pagesize.Text)>)datapagesize=Convert.ToInt32(Pagesize.Text);
pds.PageSize=datapagesize;
Zcount.Text=pds.DataSourceCount.ToString();
Zpage.Text = pds.PageCount.ToString();
intzpaging=;
if(Pageing.SelectedIndex>-)zpaging=Convert.ToInt32(Pageing.SelectedValue);
Pageing_databird(zpaging);
pds.CurrentPageIndex=Convert.ToInt32(Pageing.SelectedValue)-;
listshow_Repeater.DataSource=pds;
listshow_Repeater.DataBind();
}