第一次用AspNetPager1控件(只是显示初始的size=3,无论怎么翻页页面只是刷新但是不翻页。)希望有同样经历的帮忙解决
using System;
using System.Data;
using System.Configuration;
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;
//
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
DataSet ds;
SqlDataAdapter dr;
SqlCommand com;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlConnection con = new SqlConnection( "server=localhost;database=Templit;uid=sa;pwd= 'sa ' ");
con.Open();
com = new SqlCommand();
com.Connection = con;
com.CommandText = "select count(*) from message ";
AspNetPager1.AlwaysShow = true;
AspNetPager1.PageSize = 3;
AspNetPager1.RecordCount = (int)com.ExecuteScalar();
con.Close();
DataListDataBind();
}
}
private void DataListDataBind()
{
SqlConnection con = new SqlConnection( "server=localhost;database=Templit;uid=sa;pwd= 'sa ' ");
dr = new SqlDataAdapter( "select * from message ", con);
ds = new DataSet();
dr.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "message ");
DataList1.DataSource = ds.Tables[ "message "];
DataList1.DataBind();
}
protected voi