iam尝试使用以下代码为我的datalist使用分页...我能够做到服务器端但我怎么能做到客户端...我的意思是我已经在页面加载时绑定了我的datalist ..alli需要是允许在客户端进行分页
ASPX
<asp:LinkButton ID="LinkButton3" runat="server" CommandName="Previous" Text="<< Previous"
OnClick="Pager_Click"></asp:LinkButton>
<input id="Button6" type="button" value="close" onclick="Hidee2()" />
<asp:LinkButton ID="LinkButton4" runat="server" CommandName="Next" Text="Next >>"
OnClick="Pager_Click"></asp:LinkButton>
coodebhind
private int CurrentPage = 1;
private int ItemsPerPage = 4;
protected void Page_Load(object sender, EventArgs e)
{
int TotalRows = this.BindList(1);
this.Prepare_Pager(TotalRows);
}
//this binds the datalist
private int BindList(int PageNo)
{
int TotalRows = 0;
DataTable dt = new DataTable();
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["DSN"]);
SqlDataAdapter sda = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand("spx_Pager");
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@PageNo", SqlDbType.Int).Value = PageNo;
cmd.Parameters.Add("@ItemsPerPage", SqlDbType.Int).Value = ItemsPerPage;
cmd.Parameters.Add("@TotalRows", SqlDbType.Int).Direction = ParameterDirection.Output;
cmd.Connection = con;
try
{
con.Open();
sda.SelectCommand = cmd;
sda.Fill(dt);
DataList1.DataSource = dt;
DataList2.DataSource = dt;
DataList3.DataSource = dt;
DataList4.DataSource = dt;
DataList1.DataBind();
DataList2.DataBind();
DataList3.DataBind();
DataList4.DataBind();
TotalRows = Convert.ToInt32(cmd.Parameters["@TotalRows"].Value);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
con.Close();
sda.Dispose();
con.Dispose();
}
return TotalRows;
}
//This prepaes pager for my datalist
private void Prepare_Pager(int TotalRows)
{
int intPageCount = this.CalculateTotalPages(TotalRows);
if (intPageCount > 1 && this.CurrentPage < intPageCount)
{
this.lnkNext.Enabled = true;
}
if (this.CurrentPage != 1)
{
this.lnkPrev.Enabled = true;
}
else
{
this.lnkPrev.Enabled = false;
}
}
//This is managing my pager click events for pervious and next link buttons above
protected void Pager_Click(object sender, EventArgs e)
{
LinkButton lnkPager = (LinkButton)sender;
int PageNo = 1;
switch (lnkPager.CommandName)
{
case "Previous":
PageNo = this.CurrentPage - 1;
break;
case "Next":
PageNo = this.CurrentPage + 1;
break;
}
int TotalRows = this.BindList(PageNo);
int PageCount = this.CalculateTotalPages(TotalRows);
ViewState["CurrentPage"] = PageNo;
if (PageNo == 1)
{
lnkPrev.Enabled = false;
}
else
{
lnkPrev.Enabled = true;
}
if (PageNo == PageCount)
{
lnkNext.Enabled = false;
}
else
{
lnkNext.Enabled = true;
}
}
答案 0 :(得分:0)
您可以使用.netslackers DataControls(http://dotnetslackers.com/projects/AjaxDataControls/)
这些是纯客户端控件