请看我的代码.aspx.cs代码如下
public string news()
{ string strSql = "SELECT * FROM news n,class c where n.classid=c.classid order by newsid desc";
string strConnection = ConfigurationSettings.AppSettings["dns"];
SqlConnection objConnection = new SqlConnection(strConnection);
objConnection.Open();
SqlCommand cmd = new SqlCommand(strSql, objConnection);
SqlDataReader dr = cmd.ExecuteReader();
string strBody = null;
while (dr.Read())
{ strBody += "<li>"+dr["newtitle"]+"</li>";
}
dr.Close();
objConnection.Close();
return strBody;
}在.aspx中通过<%=news()%>获得所有的满足条件的数据,我现在想对这些数据进行分页显示,请问该怎么加代码呢?谢谢
public string news()
{ string strSql = "SELECT * FROM news n,class c where n.classid=c.classid order by newsid desc";
string strConnection = ConfigurationSettings.AppSettings["dns"];
SqlConnection objConnection = new SqlConnection(strConnection);
objConnection.Open();
SqlCommand cmd = new SqlCommand(strSql, objConnection);
SqlDataReader dr = cmd.ExecuteReader();
string strBody = null;
while (dr.Read())
{ strBody += "<li>"+dr["newtitle"]+"</li>";
}
dr.Close();
objConnection.Close();
return strBody;
}在.aspx中通过<%=news()%>获得所有的满足条件的数据,我现在想对这些数据进行分页显示,请问该怎么加代码呢?谢谢
或者datagridview来结合。
或者用分页控件
2、用repeater 或者datalist 结合分页控件。控件可以参考: www.webdiyer.com分页代码网上很多!
分页代码如下:private int curpage;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
DataTable dt3=new DataTable();
dt3=s3.getdata("select * from liuyan");
PagedDataSource pds=new PagedDataSource();
pds.DataSource=dt3.DefaultView;
pds.AllowPaging=true;
pds.PageSize=3;
if(Request.QueryString["page"]!=null)
this.curpage=Convert.ToInt32(Request.QueryString["page"]);
else
this.curpage=1;
pds.CurrentPageIndex=curpage-1;
if(!pds.IsFirstPage)
{
this.HyperLink1.Enabled=true;
}
if(!pds.IsLastPage)
{
this.HyperLink2.Enabled=true;
}
this.HyperLink1.NavigateUrl=Request.CurrentExecutionFilePath+"?page="+Convert.ToString(this.curpage-1);
this.HyperLink2.NavigateUrl=Request.CurrentExecutionFilePath+"?page="+Convert.ToString(this.curpage+1);
this.DataList1.DataSource=pds;
this.DataList1.DataBind();
}
http://blog.csdn.net/amandag/archive/2008/07/14/2646472.aspx