1、在權限判斷代碼後面增加如下代碼
VSDataTable1 = new DataSet();
public void BindRadGrid()
{
//...
this.RadGrid1.DataSource = ds;
this.RadGrid1.DataBind();
ViewState["ajbb"] = ds;
}
//RadGrid分頁功能擴充代碼
protected void RadGrid1_PageIndexChanged(object source, Telerik.WebControls.GridPageChangedEventArgs e)
{
//分頁代碼
this.RadGrid1.DataSource = VSDataTable1;
this.RadGrid1.CurrentPageIndex = e.NewPageIndex;
this.RadGrid1.DataBind();
}
#region 分頁功能擴充 2012-06-26
public void btnHidden_Click(object sender, EventArgs e)
{
int currentPageIndex = int.Parse(hf.Value);
this.RadGrid1.DataSource = VSDataTable1;
this.RadGrid1.CurrentPageIndex = currentPageIndex-1;
this.RadGrid1.DataBind();
}
#endregion
#region 分頁通用代碼
/// <summary>
/// 存放在ViewState的DataTable
/// </summary>
private DataSet VSDataTable1
get { return ViewState["ajbb"] as DataSet; }
set { ViewState["ajbb"] = value; }
/// <summary>
/// 普通的綁定資料
private void PageDataBind()
/// 綁定資料加換頁
/// <param name="getPageIndex">新頁面Index</param>
private void PageDataBind(Int32 getPageIndex)
this.RadGrid1.CurrentPageIndex = getPageIndex;
#endregion
2、前台頁面中
将RadGrid中的<PagerStyle/>替換成"></PagerStyle>
<PagerStyle Mode="NextPrevAndNumeric" NextPagesToolTip="下一頁" NextPageText="下一頁" NextPageToolTip="下一頁"
PagerTextFormat="分頁&nbsp;:&nbsp;{4} &nbsp;<input type='text' name='txtNum' id='txtNum' value='1' style='width:20px'/><input type='button' id='btnConfirm' value='确定' onclick='splitPageByHand();'/>"
PrevPagesToolTip="上一頁" PrevPageText="上一頁" PrevPageToolTip="上一頁"></PagerStyle>
3、在</rad:Grid>後面增加2個控件,代碼如下:
<asp:HiddenField ID="hf" runat="server" />
<asp:Button ID="btnHidden" runat="server" Style="display: none;" OnClick="btnHidden_Click" />
4、在</html>标記後面添加如下js代碼
<!--通用手動分頁代碼-->
<script type="text/javascript">
//手動填寫頁碼進行分頁跳轉
function splitPageByHand() {
if (!isNaN(document.getElementById("txtNum").value)) {
if (document.getElementById("txtNum").value > parseInt('<%=RadGrid1.PageCount%>') || document.getElementById("txtNum").value <= 0) {
alert('輸入數字不在範圍内!');
document.getElementById("txtNum").value = "1";
}
else {
document.getElementById("hf").value = document.getElementById("txtNum").value;
document.getElementById("btnHidden").click();
}
else {
alert('請輸入數字!');
document.getElementById("txtNum").value = "1";
//為input控件重新指派
if(document.getElementById("txtNum")!=null){
document.getElementById("txtNum").value = '<%=RadGrid1.CurrentPageIndex+1 %>';
</script>
以下是代碼