一、分页
前台代码
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" OnPageIndexChanging="GridView1_PageIndexChanging"
PageSize="3" OnDataBound="GridView1_DataBound">
<PagerSettings Mode="NextPrevious" NextPageText="下一页>>" PreviousPageText="<<上一页" />
</asp:GridView>
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br />
<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
<asp:GridView ID="GridView2" runat="server">
后台代码
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack) bindgrid();
}
void bindgrid()
{
//查询student数据库获取结果集ds
string sqlconnstr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
DataSet ds = new DataSet();
using (SqlConnection sqlconn = new SqlConnection(sqlconnstr))
{
SqlDataAdapter sqld = new SqlDataAdapter("select * from student", sqlconn);
sqld.Fill(ds, "tabstudent");
}
//以数据集中名为tabstudent的DataTable作为数据源,为控件绑定数据
GridView1.DataSource = ds.Tables["tabstudent"].DefaultView;
GridView1.DataBind();
}
protected void GridView1_DataBound(object sender, EventArgs e)
{