日期:2014-05-17 浏览次数:20541 次
<%@ Page Language="C#" Debug="true" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> // 设置每页显示的行数 int TotalRowCount = 12; protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { System.Data.DataTable dt = new System.Data.DataTable(); System.Data.DataRow dr; dt.Columns.Add(new System.Data.DataColumn("Id", typeof(System.Int32))); dt.Columns.Add(new System.Data.DataColumn("Name", typeof(System.String))); for (int i = 0; i < 8; i++) { dr = dt.NewRow(); dr[0] = i.ToString(); dr[1] = "【孟子E章】" + i.ToString(); dt.Rows.Add(dr); } System.Data.DataView dv = dt.DefaultView; dv.Sort = "Id DESC"; //排序 int addCount = TotalRowCount - dv.Table.Rows.Count; for (int i = 0; i < addCount; i++) dv.Table.Rows.Add(); GridView1.DataSource = dt; GridView1.DataBind(); } } </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>自动填充固定行数的 GridView</title> </head> <body> <form id="form1" runat="server"> <asp:GridView ID="GridView1" runat="server"> </asp:GridView> </form> </body> </html>