主题:DataList分页问题,请指教
这个程序是接受传过来的参数,然后查询数据库,用DataList把查询结果分页显示
但是一点下一页,就报错。请大虾帮我看看
private void Page_Load(object sender, System.EventArgs e)
{
string ad=Request.QueryString["itemid"]; //接收传来的参数
string str="SELECT biaoti,neirong FROM TABLE1 WHERE ck="+ad; //从数据库中查询
SqlConnection mycon=new SqlConnection(ConfigurationSettings.AppSettings["con"]);//连接数据库
SqlDataAdapter mycom=new SqlDataAdapter(str,mycon);
mycon.Open();
DataSet ds=new DataSet();
mycom.Fill(ds); //填充DataSet
//实现分页
PagedDataSource objpage=new PagedDataSource();
objpage.DataSource=ds.Tables[0].DefaultView; //设定数据源
objpage.AllowPaging=true; //设置分页
objpage.PageSize=3; //设置每页显示的行数
int curpage;
if(Request.QueryString["page"]!=null) //判断是否有页面跳转
curpage=Convert.ToInt32(Request.QueryString["page"]);
else
curpage=1;
objpage.CurrentPageIndex=curpage-1; //当前页的索引
if(!objpage.IsFirstPage)
HyperLink1.NavigateUrl=Request.CurrentExecutionFilePath+"?page="+(curpage-1);
if(!objpage.IsLastPage)
HyperLink2.NavigateUrl=Request.CurrentExecutionFilePath+"?page"+(curpage+1);
datalist1.DataSource=objpage; //设定DataList的数据源
datalist1.DataBind(); //绑定数据源
ds.Dispose(); //释放DataSet
mycon.Close();
但是一点下一页,就报错。请大虾帮我看看
private void Page_Load(object sender, System.EventArgs e)
{
string ad=Request.QueryString["itemid"]; //接收传来的参数
string str="SELECT biaoti,neirong FROM TABLE1 WHERE ck="+ad; //从数据库中查询
SqlConnection mycon=new SqlConnection(ConfigurationSettings.AppSettings["con"]);//连接数据库
SqlDataAdapter mycom=new SqlDataAdapter(str,mycon);
mycon.Open();
DataSet ds=new DataSet();
mycom.Fill(ds); //填充DataSet
//实现分页
PagedDataSource objpage=new PagedDataSource();
objpage.DataSource=ds.Tables[0].DefaultView; //设定数据源
objpage.AllowPaging=true; //设置分页
objpage.PageSize=3; //设置每页显示的行数
int curpage;
if(Request.QueryString["page"]!=null) //判断是否有页面跳转
curpage=Convert.ToInt32(Request.QueryString["page"]);
else
curpage=1;
objpage.CurrentPageIndex=curpage-1; //当前页的索引
if(!objpage.IsFirstPage)
HyperLink1.NavigateUrl=Request.CurrentExecutionFilePath+"?page="+(curpage-1);
if(!objpage.IsLastPage)
HyperLink2.NavigateUrl=Request.CurrentExecutionFilePath+"?page"+(curpage+1);
datalist1.DataSource=objpage; //设定DataList的数据源
datalist1.DataBind(); //绑定数据源
ds.Dispose(); //释放DataSet
mycon.Close();