test.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %>
<%@ Register Src="test.ascx" TagName="test" TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1" PageSize="5">
<Columns>
<asp:BoundField DataField="tlr_13_0" HeaderText="tlr_13_0" InsertVisible="False"
ReadOnly="True" SortExpression="tlr_13_0" />
<asp:BoundField DataField="tlr_13_1" HeaderText="tlr_13_1" SortExpression="tlr_13_1" />
<asp:BoundField DataField="tlr_13_2" HeaderText="tlr_13_2" SortExpression="tlr_13_2" />
<asp:BoundField DataField="tlr_13_3" HeaderText="tlr_13_3" SortExpression="tlr_13_3" />
</Columns>
<PagerTemplate>
<uc1:test ID="Test1" runat="server" />
</PagerTemplate>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:tlrConnectionString %>"
SelectCommand="SELECT [tlr_13_0], [tlr_13_1], [tlr_13_2], [tlr_13_3] FROM [tlr_13]">
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
模版:
test.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="test.ascx.cs" Inherits="test" %>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
test.ascx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class test : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GridView gv = (GridView)Page.FindControl("GridView1");
//DropDownList1.
DropDownList1.Items.Clear();
for (int i = 1; i <= gv.PageCount; i++)
{
DropDownList1.Items.Add(i.ToString());
}
}
}
}