datalist 不分页能显示绑定数据分页后不能显示了
后台代码:stringstrSQL;intiPageSize=12;//每页显示的商品数intiMaxPage;//总页数intiCurPage;//当前页数if(Req...
后台代码:
string strSQL;
int iPageSize = 12; //每页显示的商品数
int iMaxPage; //总页数
int iCurPage; //当前页数
if (Request.QueryString["page"] != "")
iCurPage = Convert.ToInt32(Request.QueryString["page"]);
else
iCurPage = 1;
strSQL = "SELECT count(*) FROM product";
int intTotalRec = Convert.ToInt32(DbManager.ExecuteScalar(strSQL));//求总记录数
if (intTotalRec <= iPageSize)
Panel1.Visible = false;
else
{
Panel1.Visible = true;
if (intTotalRec % iPageSize == 0)
iMaxPage = intTotalRec / iPageSize;//求总页数
else
iMaxPage = intTotalRec / iPageSize + 1;
if (iMaxPage == 0)
iMaxPage = 1;
if (iCurPage < 1)
iCurPage = 1;
else
if (iCurPage > iMaxPage)
iCurPage = iMaxPage;
if (intTotalRec != 0)
{
if (iCurPage == 1)
{
strSQL = "SELECT top 3 PID,Pname,Pic FROM product order by PID desc";
dltMoreProduct.DataSource = DbManager.ExecuteQuery(strSQL);
dltMoreProduct.DataBind();
}
else//排除式查询
{
strSQL = "SELECT top 3 PID,Pname,Pic FROM product WHERE PID not in(SELECT top " + (iCurPage - 1) * 3 + " PID FROM product ORDER BY PID desc) ORDER BY PID desc";
dltMoreProduct.DataSource = DbManager.ExecuteQuery(strSQL);
dltMoreProduct.DataBind();
}
}
lblTotal.Text = "共有" + intTotalRec.ToString() + "条记录 当前是第" + iCurPage.ToString() + "/" + iMaxPage.ToString() + "页 ";
if (iCurPage != 1)
{
hlFirst.NavigateUrl = Request.FilePath + "?page=1";
hlPre.NavigateUrl = Request.FilePath + "?page=" + (iCurPage - 1);
}
if (iCurPage != iMaxPage)
{
hlNext.NavigateUrl = Request.FilePath + "?page=" + (iCurPage + 1);
hlLast.NavigateUrl = Request.FilePath + "?page=" + iMaxPage;
}
}
}
protected void btnGoPage_Click(object sender, EventArgs e)
{
int iCurPage = 1;
if (txtGoPage.Text != "")
iCurPage = Convert.ToInt32(txtGoPage.Text);
Response.Redirect(Request.FilePath + "?page=" + iCurPage);
}
数据绑定
<table class="style1">
<tr>
<td>
<a href="productshow.aspx?id=<%# Eval("PID") %>">
<img src="imagesproduct/<%# Eval("Pic") %>" alt="" /></a>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblproductname" runat="server" Text='<%# Eval("Pname") %>'></asp:Label>
</td>
</tr>
</table> 展开
string strSQL;
int iPageSize = 12; //每页显示的商品数
int iMaxPage; //总页数
int iCurPage; //当前页数
if (Request.QueryString["page"] != "")
iCurPage = Convert.ToInt32(Request.QueryString["page"]);
else
iCurPage = 1;
strSQL = "SELECT count(*) FROM product";
int intTotalRec = Convert.ToInt32(DbManager.ExecuteScalar(strSQL));//求总记录数
if (intTotalRec <= iPageSize)
Panel1.Visible = false;
else
{
Panel1.Visible = true;
if (intTotalRec % iPageSize == 0)
iMaxPage = intTotalRec / iPageSize;//求总页数
else
iMaxPage = intTotalRec / iPageSize + 1;
if (iMaxPage == 0)
iMaxPage = 1;
if (iCurPage < 1)
iCurPage = 1;
else
if (iCurPage > iMaxPage)
iCurPage = iMaxPage;
if (intTotalRec != 0)
{
if (iCurPage == 1)
{
strSQL = "SELECT top 3 PID,Pname,Pic FROM product order by PID desc";
dltMoreProduct.DataSource = DbManager.ExecuteQuery(strSQL);
dltMoreProduct.DataBind();
}
else//排除式查询
{
strSQL = "SELECT top 3 PID,Pname,Pic FROM product WHERE PID not in(SELECT top " + (iCurPage - 1) * 3 + " PID FROM product ORDER BY PID desc) ORDER BY PID desc";
dltMoreProduct.DataSource = DbManager.ExecuteQuery(strSQL);
dltMoreProduct.DataBind();
}
}
lblTotal.Text = "共有" + intTotalRec.ToString() + "条记录 当前是第" + iCurPage.ToString() + "/" + iMaxPage.ToString() + "页 ";
if (iCurPage != 1)
{
hlFirst.NavigateUrl = Request.FilePath + "?page=1";
hlPre.NavigateUrl = Request.FilePath + "?page=" + (iCurPage - 1);
}
if (iCurPage != iMaxPage)
{
hlNext.NavigateUrl = Request.FilePath + "?page=" + (iCurPage + 1);
hlLast.NavigateUrl = Request.FilePath + "?page=" + iMaxPage;
}
}
}
protected void btnGoPage_Click(object sender, EventArgs e)
{
int iCurPage = 1;
if (txtGoPage.Text != "")
iCurPage = Convert.ToInt32(txtGoPage.Text);
Response.Redirect(Request.FilePath + "?page=" + iCurPage);
}
数据绑定
<table class="style1">
<tr>
<td>
<a href="productshow.aspx?id=<%# Eval("PID") %>">
<img src="imagesproduct/<%# Eval("Pic") %>" alt="" /></a>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblproductname" runat="server" Text='<%# Eval("Pname") %>'></asp:Label>
</td>
</tr>
</table> 展开
1个回答
展开全部
首先想问你,你这样写了,HyperLink能触发??
追问
这个是我从以前的老师做的网站上考下了的 什么都没有变 就是少了几个数据绑定 为什么还是不能使用
追答
就以你现成的代码,把
if (iCurPage != 1)
{
hlFirst.NavigateUrl = Request.FilePath + "?page=1";
hlPre.NavigateUrl = Request.FilePath + "?page=" + (iCurPage - 1);
}
if (iCurPage != iMaxPage)
{
hlNext.NavigateUrl = Request.FilePath + "?page=" + (iCurPage + 1);
hlLast.NavigateUrl = Request.FilePath + "?page=" + iMaxPage;
}
这里用到的HyperLink,全换成LinkButton,然后改成
if (iCurPage != 1)
{
hlFirst.ToolTip = "?page=1";
hlPre.ToolTip = "?page=" + (iCurPage - 1);
}
if (iCurPage != iMaxPage)
{
hlNext.ToolTip = "?page=" + (iCurPage + 1);
hlLast.ToolTip = "?page=" + iMaxPage;
}
在触发每个LinkButton的单击事件
protected void hlFirst_Click(object sender, EventArgs e)
{
Response.Redirect("当前页面.aspx"+ hlFirst.ToolTip);
}
protected void hlPre_Click(object sender, EventArgs e)
{
Response.Redirect("当前页面.aspx" + hlPre.ToolTip);
}
protected void hlNext_Click(object sender, EventArgs e)
{
Response.Redirect("当前页面.aspx" + hlNext.ToolTip);
}
protected void hlLast_Click(object sender, EventArgs e)
{
Response.Redirect("当前页面.aspx" + hlLast.ToolTip);
}
这样应该就可以了。。顺便提一句,这个分页写的很蛋疼!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询