1前台代码:

<asp:GridView ID="GridView1" runat="server" AllowPaging="True"  onpageindexchanging="GridView1_PageIndexChanging"
AutoGenerateColumns="False" onrowcommand="GridView1_RowCommand" onrowdatabound="GridView1_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="表单号">
<ItemTemplate>
<%#Eval("FormNum")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="项目经理">
<ItemTemplate>
<%#Eval("PMName")%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerTemplate>
<asp:Label ID="lblPage" runat="server" Text='<%#(((GridView)Container.NamingContainer).PageIndex+1)+"/"+(((GridView)Container.NamingContainer).PageCount) %>'></asp:Label>
<asp:LinkButton ID="lbnFirst" runat="server" Text="首页" Enabled='<%#((GridView)Container.NamingContainer).PageIndex!=0%>'
CommandName="Page" CommandArgument="First"></asp:LinkButton>
<asp:LinkButton ID="lbnPrev" runat="server" Text="上一页" Enabled='<%#((GridView)Container.NamingContainer).PageIndex!=0%>'
CommandName="Page" CommandArgument="Prev"></asp:LinkButton>
<asp:LinkButton ID="lbnNext" runat="server" Text="下一页" Enabled='<%#((GridView)Container.NamingContainer).PageIndex!=(((GridView)Container.NamingContainer).PageCount-1)%>'
CommandName="Page" CommandArgument="Next"></asp:LinkButton>
<asp:LinkButton ID="lbnLast" runat="server" Text="尾页" Enabled='<%#((GridView)Container.NamingContainer).PageIndex!=(((GridView)Container.NamingContainer).PageCount-1)%>'
CommandName="Page" CommandArgument="Last"></asp:LinkButton>
到第<asp:TextBox ID="inPageNum" runat="server" Width="80px"></asp:TextBox>页  
<asp:Button ID="Button1" runat="server" Text="Go" CommandName="Go" Width="50px" Height="20px" />
</PagerTemplate>
</asp:GridView>

2、后台代码

 static DataTable table = null;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bind();
}
}
public void Bind()
{
GridView1.DataSource = Select();
GridView1.DataBind();
}
public DataTable Select()
{
string sql = "select FormNum,PMName from v_Guru_Product_License_Applied ";
return DbHelper.Instance.CreateDataTable(CommandType.Text, sql);
} protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
try
{
GridView1.PageIndex = e.NewPageIndex;
if (table == null)
{
Bind();
}
else
{
GridView1.DataSource = table;
GridView1.DataBind();
}
TextBox tb = (TextBox)GridView1.BottomPagerRow.FindControl("inPageNum");
tb.Text = (GridView1.PageIndex + 1).ToString();
}
catch { }
} protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
int i;
for (i = 0; i <= GridView1.Rows.Count; i++)
{
if (e.Row.RowType == DataControlRowType.DataRow) //首先判断是否是数据行
{
//当鼠标停留时更改背景色
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#BBA1E0'");
//当鼠标移开时还原背景色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
//单击行的任意列会自动选中此行
e.Row.Attributes.Add("onclick", "__doPostBack('GridView1','Select$" + e.Row.RowIndex + "')");
}
}
} protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Go")//跳转
{
try
{
TextBox tb = (TextBox)GridView1.BottomPagerRow.FindControl("inPageNum");
int num = int.Parse(tb.Text);
GridViewPageEventArgs ea = new GridViewPageEventArgs(num - 1);
GridView1_PageIndexChanging(null, ea);
}
catch { }
}
}
}

最新文章

  1. 【Java每日一题】20161125
  2. python类——黑板客老师课程学习
  3. oracle 驱动安装备忘
  4. LeetCode 5 Longest Palindromic Substring(最长子序列)
  5. apache重写规则自动追加查询参数QSA
  6. jQuery ID与Class性能对比之一
  7. CQRS学习——集成ASP.NET Identity[其五]
  8. left (outer) join , right (outer) join, full (outer) join, (inner) join, cross join 区别
  9. 数据结构-------单链表(C++)
  10. [ZETCODE]wxWidgets教程八:组件专题1
  11. 对 sql server 数据库的备份进行加密
  12. jstree 学习
  13. .NET Core TDD 前传: 编写易于测试的代码 -- 依赖项
  14. 第十五节:深入理解async和await的作用及各种适用场景和用法
  15. get/post比较
  16. February 28th, 2018 Week 9th Wednesday
  17. OpenCV-Python入门教程1-图片
  18. LoadRunner接口测试标准模板
  19. canvas画布内部重复画圆
  20. 【第二十六章】 hystrix-dashboard + turbine

热门文章

  1. MFS分布式文件系统【3】存储节点 CHUNK SERVER 部署
  2. violet
  3. 骑马修栅栏 Riding the Fences
  4. Cause: java.sql.SQLDataException: ORA-01861: 文字与格式字符串不匹配
  5. CKEditor与CKFinder学习--自定义界面及按钮事件捕获
  6. Pregel的应用实例——单源最短路径
  7. 了解linux web的监听工具
  8. .nett Core之路由配置
  9. 针对list&lt;object&gt;中的对象数据的一些简单处理
  10. 拦截器一Interceptor