创建脚本
<div style="filter:glow(color=#ffff00,strength=5,enabled=1)blendTrans(duration=1);FONT-SIZE:13px;HEIGHT:1px;"><strong>
<div style="font-size:12px;left: 201px; width: 448px; position:relative; top: -16px; height: 13px">
<asp:LinkButton ID="Lin_FirstPage" style="font-size:12px" runat="server" OnClick="Lin_FirstPage_Click">第一页</asp:LinkButton>
<asp:LinkButton ID="Lin_FrontPage" style="font-size:12px" runat="server" OnClick="Lin_FrontPage_Click">上一页</asp:LinkButton>
<asp:LinkButton ID="Lin_NextPage" style="font-size:12px" runat="server" OnClick="Lin_NextPage_Click">下一页</asp:LinkButton>
<asp:LinkButton ID="Lin_LastPage" style="font-size:12px" runat="server" OnClick="Lin_LastPage_Click">最后一页</asp:LinkButton>
当前是第<asp:Label ID="Lab_CurrentPage" runat="server" style="font-size:12px" Text="1" Width="7px"></asp:Label>页/共
<asp:Label ID="Lab_TotalPage" runat="server" Text="1" Width="10px"></asp:Label>页</div>
</strong></div>
分页绑定代码
protected void Page_Load(object sender, EventArgs e)
{
RefreshDataGrid();
}
//分页绑定数据
publicData F = new publicData();
protected void RefreshDataGrid()
{
SqlConnection cnn = F.connection();
cnn.Open();
try
{
int iCurPages = Convert.ToInt32(Lab_CurrentPage.Text.Trim());
PagedDataSource PDS_PageData = new PagedDataSource();
DataSet mydataset = new DataSet();
mydataset.Clear();
string str1 = "select * from explainanswer";
SqlDataAdapter sda = new SqlDataAdapter(str1, cnn);
sda.Fill(mydataset, "judge");
if (mydataset != null)
{
if (mydataset.Tables[0].Rows.Count != 0)
{
PDS_PageData.DataSource = mydataset.Tables[0].DefaultView;
//允许分页
PDS_PageData.AllowPaging = true;
//每页最多显示10条内容
PDS_PageData.PageSize = 10;
//当前显示的页面是....数组下标
PDS_PageData.CurrentPageIndex = iCurPages - 1;
//对总页面的数量赋值
Lab_TotalPage.Text = Convert.ToString(PDS_PageData.PageCount);
//把分页后的数据集直接赋值
this.GridView1.DataSource = PDS_PageData;
//数据绑定并且显示
this.GridView1.DataBind();
////设置列宽
//KDB_Select.DBConnectStop();
}
}
}
catch (Exception)
{
}
}
protected void Lin_FirstPage_Click(object sender, EventArgs e)
{
Lab_CurrentPage.Text = "1";
RefreshDataGrid();
}
protected void Lin_FrontPage_Click(object sender, EventArgs e)
{
if (int.Parse(Lab_CurrentPage.Text.Trim()) - 1 != 0)
{
Lab_CurrentPage.Text = (int.Parse(Lab_CurrentPage.Text.Trim()) - 1).ToString();
RefreshDataGrid();
}
else
{
Response.Write("<script language='javascript'>alert('已经是第一页!');</script>");
}
}
protected void Lin_NextPage_Click(object sender, EventArgs e)
{
if ((int.Parse(Lab_CurrentPage.Text.Trim()) + 1) != (int.Parse(Lab_TotalPage.Text) + 1))
{
Lab_CurrentPage.Text = (int.Parse(Lab_CurrentPage.Text.Trim()) + 1).ToString();
RefreshDataGrid();
}
else
{
Response.Write("<script language='javascript'>alert('已经是最后一页!');</script>");
}
}
protected void Lin_LastPage_Click(object sender, EventArgs e)
{
Lab_CurrentPage.Text = Lab_TotalPage.Text;
RefreshDataGrid();
}