
datalist 分页问题
publicpartialclassprosmll:System.Web.UI.Page{dbDB=newdb();protectedvoidPage_Load(obje...
public partial class prosmll : System.Web.UI.Page
{
db DB = new db();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bind();
}
}
public void bind()
{
string idd = Request.QueryString["id"];
string sql = "select * from tb_product where csort=" + idd;
SqlDataAdapter objCommand = new SqlDataAdapter(sql,DB.getcon());
DataSet ds = new DataSet();
objCommand.Fill(ds);
//对PagedDataSource 对象的相关属性赋值
PagedDataSource pds = new PagedDataSource();
pds.AllowPaging = true;
pds.DataSource = ds.Tables[0].DefaultView;
pds.PageSize = 5;
int CurPage;
//当前页面从Page查询参数获取
if (Request.QueryString["Page"] != null)
{
CurPage = Convert.ToInt32(Request.QueryString["Page"]);
}
else
{ CurPage =1;}
pds.CurrentPageIndex = CurPage - 1;
this.lblCurrentPage.Text = "Page: " + CurPage.ToString();
if (!pds.IsFirstPage)
{
this.lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1);
}
if (!pds.IsLastPage)
{
this.lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1);
}
//把PagedDataSource 对象赋给Repeater控件
DataList1.DataSource = pds;
DataList1.DataBind();
}
运行第一页显示出,运行下一页出现o bjCommand.Fill(ds); '=' 附近有语法错误。百思不得其解
呵呵。搞定了,程序没错,错在this.lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1); 把Request.CurrentExecutionFilePath换成真实的地址久OKle 展开
{
db DB = new db();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bind();
}
}
public void bind()
{
string idd = Request.QueryString["id"];
string sql = "select * from tb_product where csort=" + idd;
SqlDataAdapter objCommand = new SqlDataAdapter(sql,DB.getcon());
DataSet ds = new DataSet();
objCommand.Fill(ds);
//对PagedDataSource 对象的相关属性赋值
PagedDataSource pds = new PagedDataSource();
pds.AllowPaging = true;
pds.DataSource = ds.Tables[0].DefaultView;
pds.PageSize = 5;
int CurPage;
//当前页面从Page查询参数获取
if (Request.QueryString["Page"] != null)
{
CurPage = Convert.ToInt32(Request.QueryString["Page"]);
}
else
{ CurPage =1;}
pds.CurrentPageIndex = CurPage - 1;
this.lblCurrentPage.Text = "Page: " + CurPage.ToString();
if (!pds.IsFirstPage)
{
this.lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1);
}
if (!pds.IsLastPage)
{
this.lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1);
}
//把PagedDataSource 对象赋给Repeater控件
DataList1.DataSource = pds;
DataList1.DataBind();
}
运行第一页显示出,运行下一页出现o bjCommand.Fill(ds); '=' 附近有语法错误。百思不得其解
呵呵。搞定了,程序没错,错在this.lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1); 把Request.CurrentExecutionFilePath换成真实的地址久OKle 展开
2个回答
展开全部
应该是你的SQL语句写错了吧
还有 你也没有设置数据表名
aaa.fill(ds,"TableName");
还有 你也没有设置数据表名
aaa.fill(ds,"TableName");
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询