前台代码如下
<%@ Page Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="showzbbyfl.aspx.cs" Inherits="JK.showzbbyfl" Title="无标题页" %>
<%@ Import Namespace="System.Data" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script type="text/javascript">
<!--
function mOvr(src,clrOver) {
if (!src.contains(event.fromElement)) {
src.style.cursor = 'hand';
src.bgColor = clrOver;
}
}
function mOut(src,clrIn) {
if (!src.contains(event.toElement)) {
src.style.cursor = 'default';
src.bgColor = clrIn;
}
}
function mClk(src) {
if(event.srcElement.tagName=='TD'){
src.children.tags('A')[0].click();
}
}
// -->
</script></asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div class="mian">
<p>你的位置是》》<asp:Label ID="Label1" runat="server"></asp:Label></p>
<table style="text-align:center; border:1px solid black;">
<tr>
<th>招标预算</th>
<th>招标主题</th>
<th>我要竞标</th>
</tr>
<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
<ItemTemplate>
<tr onMouseOut="mOut(this,'#FFFFFF');" onMouseOver="mOvr(this,'#CCCCCC')"><td style="width:200px; height:20px;"><%#Eval("zbprice") %></td>
<td style="width:600px;" >
<a href='showzhaobiao.aspx?zbid=<%#Eval("id") %>'><%#Eval("zbtitle") %></a></td>
<td style="width:100px;"><a href='jbadd.aspx?zbid=<%#Eval("id") %>'>我要竞标</a></td></tr>
</ItemTemplate>
<FooterTemplate>
<tr><td colspan="3">
共<asp:Label ID="lblpc" runat="server" Text="Label"></asp:Label>页
当前为第
<asp:Label ID="lblp" runat="server" Text="Label"></asp:Label>页
<asp:HyperLink ID="hlfir" runat="server" Text="首页"></asp:HyperLink>
<asp:HyperLink ID="hlp" runat="server" Text="上一页"></asp:HyperLink>
<asp:HyperLink ID="hln" runat="server" Text="下一页"></asp:HyperLink>
<asp:HyperLink ID="hlla" runat="server" Text="尾页"></asp:HyperLink>
跳至第
<asp:DropDownList ID="ddlp" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlp_SelectedIndexChanged" >
</asp:DropDownList>页</td></tr>
</FooterTemplate>
</asp:Repeater>
</table>
</div>
</asp:Content>后台代码如下:
using System.Configuration;
using System.Data;
using System.Linq;
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.Xml.Linq;
using BLL;
using MODEL;namespace JK
{
public partial class showzbbyfl : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
int smallclass = Convert.ToInt32(Request.QueryString["id"]);
smallclassmanager nm = new smallclassmanager();
SMALLCLASS d = nm.selectsnamebyid(smallclass);
Label1.Text = d.Sname; Repeater1.DataSource = pds();
Repeater1.DataBind();
}
}
private PagedDataSource pds()
{
int smallclass = Convert.ToInt32(Request.QueryString["id"]);
DataTable dt = new DataTable();
dt = new zhaobiaomanager().selectzbbysmallclass(smallclass); PagedDataSource pds = new PagedDataSource();
pds.DataSource = dt.DefaultView;
pds.AllowPaging = true;
pds.PageSize = 5; pds.CurrentPageIndex = Convert.ToInt32(Request.QueryString["page"]);
return pds;
}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Footer)
{
DropDownList ddlp = (DropDownList)e.Item.FindControl("ddlp"); HyperLink lpfirst = (HyperLink)e.Item.FindControl("hlfir");
HyperLink lpprev = (HyperLink)e.Item.FindControl("hlp");
HyperLink lpnext = (HyperLink)e.Item.FindControl("hln");
HyperLink lplast = (HyperLink)e.Item.FindControl("hlla"); pds().CurrentPageIndex = ddlp.SelectedIndex; int s = Convert.ToInt32(pds().PageCount);//n为分页数
int i = Convert.ToInt32(pds().CurrentPageIndex);//i为当前页 Label lblpc = (Label)e.Item.FindControl("lblpc");
lblpc.Text = s.ToString();
Label lblp = (Label)e.Item.FindControl("lblp");
lblp.Text = Convert.ToString(pds().CurrentPageIndex + 1); if (!IsPostBack)
{
for (int j = 0; j < s; j++)
{
ddlp.Items.Add(Convert.ToString(j + 1));
}
} if (i <= 0)
{
lpfirst.Enabled = false;
lpprev.Enabled = false;
lplast.Enabled = true;
lpnext.Enabled = true;
}
else
{
lpprev.NavigateUrl = "?page=" + (i - 1);
}
if (i >= s - 1)
{
lpfirst.Enabled = true;
lplast.Enabled = false;
lpnext.Enabled = false;
lpprev.Enabled = true;
}
else
{
lpnext.NavigateUrl = "?page=" + (i + 1);
} lpfirst.NavigateUrl = "?page=0";//向本页传递参数page
lplast.NavigateUrl = "?page=" + (s - 1); ddlp.SelectedIndex = Convert.ToInt32(pds().CurrentPageIndex);//更新下拉列表框中的当前选中页序号
} }
protected void ddlp_SelectedIndexChanged(object sender, EventArgs e)
{//脚模板中的下拉列表框更改时激发
string pg = Convert.ToString((Convert.ToInt32(((DropDownList)sender).SelectedValue) - 1));//获取列表框当前选中项
Response.Redirect("showzbbyfl.aspx?page=" + pg);//页面转向
}
}
}
DAL代码如下:
//根据ID取出三级分类的名称
public SMALLCLASS selectsnamebyid(int id)
{
SMALLCLASS d = new SMALLCLASS();
DataTable dt = new DataTable();
string sql = "select * from smallclass where id=@id";
SqlParameter[] pars = new SqlParameter[]{
new SqlParameter("@id",id)
};
dt = sqlhelper.ExecuteQueryt(sql, pars, CommandType.Text);
if (dt.Rows.Count > 0)
{
d.Id = dt.Rows[0]["id"].ToString();
d.Sname = dt.Rows[0]["sname"].ToString();
d.Midclass = dt.Rows[0]["midclass"].ToString();
return d;
}
else
{
return null;
}
//根据三级分类的ID取出下面所有招标信息
public DataTable selectzbbysmallclass(int smallclass)
{
DataTable dt = new DataTable();
string flname = "selectzbbysmallclass";
SqlParameter[] pars = new SqlParameter[]{
new SqlParameter("@smallclass",smallclass)
};
dt = sqlherlper.ExecuteQueryt(flname, pars, CommandType.StoredProcedure);
if (dt.Rows.Count > 0)
{
return dt;
}
else
{
return null;
}
在我点击下一页的时候,他老是提示这样的错误:未将对象引用设置到对象的实例。 行 25: smallclassmanager nm = new smallclassmanager();
行 26: SMALLCLASS d = nm.selectsnamebyid(smallclass);
行 27: Label1.Text = d.Sname;、、这里是错误点
行 28:
行 29: Repeater1.DataSource = pds();
我测试的时候是正常的,但传递了个参数,就不合适了如果帮忙解决了,我另个号还有130分,全给
<%@ Page Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="showzbbyfl.aspx.cs" Inherits="JK.showzbbyfl" Title="无标题页" %>
<%@ Import Namespace="System.Data" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script type="text/javascript">
<!--
function mOvr(src,clrOver) {
if (!src.contains(event.fromElement)) {
src.style.cursor = 'hand';
src.bgColor = clrOver;
}
}
function mOut(src,clrIn) {
if (!src.contains(event.toElement)) {
src.style.cursor = 'default';
src.bgColor = clrIn;
}
}
function mClk(src) {
if(event.srcElement.tagName=='TD'){
src.children.tags('A')[0].click();
}
}
// -->
</script></asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div class="mian">
<p>你的位置是》》<asp:Label ID="Label1" runat="server"></asp:Label></p>
<table style="text-align:center; border:1px solid black;">
<tr>
<th>招标预算</th>
<th>招标主题</th>
<th>我要竞标</th>
</tr>
<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
<ItemTemplate>
<tr onMouseOut="mOut(this,'#FFFFFF');" onMouseOver="mOvr(this,'#CCCCCC')"><td style="width:200px; height:20px;"><%#Eval("zbprice") %></td>
<td style="width:600px;" >
<a href='showzhaobiao.aspx?zbid=<%#Eval("id") %>'><%#Eval("zbtitle") %></a></td>
<td style="width:100px;"><a href='jbadd.aspx?zbid=<%#Eval("id") %>'>我要竞标</a></td></tr>
</ItemTemplate>
<FooterTemplate>
<tr><td colspan="3">
共<asp:Label ID="lblpc" runat="server" Text="Label"></asp:Label>页
当前为第
<asp:Label ID="lblp" runat="server" Text="Label"></asp:Label>页
<asp:HyperLink ID="hlfir" runat="server" Text="首页"></asp:HyperLink>
<asp:HyperLink ID="hlp" runat="server" Text="上一页"></asp:HyperLink>
<asp:HyperLink ID="hln" runat="server" Text="下一页"></asp:HyperLink>
<asp:HyperLink ID="hlla" runat="server" Text="尾页"></asp:HyperLink>
跳至第
<asp:DropDownList ID="ddlp" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlp_SelectedIndexChanged" >
</asp:DropDownList>页</td></tr>
</FooterTemplate>
</asp:Repeater>
</table>
</div>
</asp:Content>后台代码如下:
using System.Configuration;
using System.Data;
using System.Linq;
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.Xml.Linq;
using BLL;
using MODEL;namespace JK
{
public partial class showzbbyfl : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
int smallclass = Convert.ToInt32(Request.QueryString["id"]);
smallclassmanager nm = new smallclassmanager();
SMALLCLASS d = nm.selectsnamebyid(smallclass);
Label1.Text = d.Sname; Repeater1.DataSource = pds();
Repeater1.DataBind();
}
}
private PagedDataSource pds()
{
int smallclass = Convert.ToInt32(Request.QueryString["id"]);
DataTable dt = new DataTable();
dt = new zhaobiaomanager().selectzbbysmallclass(smallclass); PagedDataSource pds = new PagedDataSource();
pds.DataSource = dt.DefaultView;
pds.AllowPaging = true;
pds.PageSize = 5; pds.CurrentPageIndex = Convert.ToInt32(Request.QueryString["page"]);
return pds;
}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Footer)
{
DropDownList ddlp = (DropDownList)e.Item.FindControl("ddlp"); HyperLink lpfirst = (HyperLink)e.Item.FindControl("hlfir");
HyperLink lpprev = (HyperLink)e.Item.FindControl("hlp");
HyperLink lpnext = (HyperLink)e.Item.FindControl("hln");
HyperLink lplast = (HyperLink)e.Item.FindControl("hlla"); pds().CurrentPageIndex = ddlp.SelectedIndex; int s = Convert.ToInt32(pds().PageCount);//n为分页数
int i = Convert.ToInt32(pds().CurrentPageIndex);//i为当前页 Label lblpc = (Label)e.Item.FindControl("lblpc");
lblpc.Text = s.ToString();
Label lblp = (Label)e.Item.FindControl("lblp");
lblp.Text = Convert.ToString(pds().CurrentPageIndex + 1); if (!IsPostBack)
{
for (int j = 0; j < s; j++)
{
ddlp.Items.Add(Convert.ToString(j + 1));
}
} if (i <= 0)
{
lpfirst.Enabled = false;
lpprev.Enabled = false;
lplast.Enabled = true;
lpnext.Enabled = true;
}
else
{
lpprev.NavigateUrl = "?page=" + (i - 1);
}
if (i >= s - 1)
{
lpfirst.Enabled = true;
lplast.Enabled = false;
lpnext.Enabled = false;
lpprev.Enabled = true;
}
else
{
lpnext.NavigateUrl = "?page=" + (i + 1);
} lpfirst.NavigateUrl = "?page=0";//向本页传递参数page
lplast.NavigateUrl = "?page=" + (s - 1); ddlp.SelectedIndex = Convert.ToInt32(pds().CurrentPageIndex);//更新下拉列表框中的当前选中页序号
} }
protected void ddlp_SelectedIndexChanged(object sender, EventArgs e)
{//脚模板中的下拉列表框更改时激发
string pg = Convert.ToString((Convert.ToInt32(((DropDownList)sender).SelectedValue) - 1));//获取列表框当前选中项
Response.Redirect("showzbbyfl.aspx?page=" + pg);//页面转向
}
}
}
DAL代码如下:
//根据ID取出三级分类的名称
public SMALLCLASS selectsnamebyid(int id)
{
SMALLCLASS d = new SMALLCLASS();
DataTable dt = new DataTable();
string sql = "select * from smallclass where id=@id";
SqlParameter[] pars = new SqlParameter[]{
new SqlParameter("@id",id)
};
dt = sqlhelper.ExecuteQueryt(sql, pars, CommandType.Text);
if (dt.Rows.Count > 0)
{
d.Id = dt.Rows[0]["id"].ToString();
d.Sname = dt.Rows[0]["sname"].ToString();
d.Midclass = dt.Rows[0]["midclass"].ToString();
return d;
}
else
{
return null;
}
//根据三级分类的ID取出下面所有招标信息
public DataTable selectzbbysmallclass(int smallclass)
{
DataTable dt = new DataTable();
string flname = "selectzbbysmallclass";
SqlParameter[] pars = new SqlParameter[]{
new SqlParameter("@smallclass",smallclass)
};
dt = sqlherlper.ExecuteQueryt(flname, pars, CommandType.StoredProcedure);
if (dt.Rows.Count > 0)
{
return dt;
}
else
{
return null;
}
在我点击下一页的时候,他老是提示这样的错误:未将对象引用设置到对象的实例。 行 25: smallclassmanager nm = new smallclassmanager();
行 26: SMALLCLASS d = nm.selectsnamebyid(smallclass);
行 27: Label1.Text = d.Sname;、、这里是错误点
行 28:
行 29: Repeater1.DataSource = pds();
我测试的时候是正常的,但传递了个参数,就不合适了如果帮忙解决了,我另个号还有130分,全给
int smallclass = Convert.ToInt32(Request.QueryString["id"]);取到值没有?
int smallclass = Convert.ToInt32(Request.QueryString["id"]);
这个的问题了
if(smallclass<=0) return; //或者转到错误页smallclassmanager nm = new smallclassmanager();
SMALLCLASS d = nm.selectsnamebyid(smallclass);if(d == null) return; //防止没有找到相应的SMALLCLASS而空引用,这个必需的Label1.Text = d.Sname;
建议LZ用aspnetpager翻页,LZ自己写个并不简单何况读起来真不是怎样http://www.cnblogs.com/myfall/articles/1759512.html上面是个简单示例,LZ可以自己网上搜一下,示例很多
http://www.cnblogs.com/yyl8781697/archive/2012/03/07/aspnetpager.html