代码运行提示未将对像引用设置到对像实例,请高手帮忙看看。错误处已标明
string sql1 = ""; int rowCount = 0; protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{ this.xianshi(); }
}
public SqlConnection GetConnection()
{
string myStr = ConfigurationManager.AppSettings["conn"].ToString();
SqlConnection myConn = new SqlConnection(myStr);
return myConn;
} private void xianshi()
{
SqlConnection myConn = GetConnection();
myConn.Open();
sql1 = this.fkcx_jj.Text;
string sqlStr = "select * from gg_gg,gg_zt where gg_gg.gg_fkzt=gg_zt.ggzt_id order by gg_zt.ggzt_mc";
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(sqlStr, myConn);
da.Fill(ds,"gg_gg");
rowCount = ds.Tables["gg_gg"].Rows.Count;
fkcx_gv.DataSource=ds.Tables["gg_gg"];
fkcx_gv.DataBind(); }
protected void NavigateToPage(object sender, CommandEventArgs e)
{
switch (e.CommandArgument.ToString())//控制转页
{
case "First"://首页
this.fkcx_gv.PageIndex = 0;
break;
case "Prev"://上一页
if (this.fkcx_gv.PageIndex > 0)
this.fkcx_gv.PageIndex -= 1;
break;
case "Next"://下一页
if (this.fkcx_gv.PageIndex < (this.fkcx_gv.PageCount - 1))
this.fkcx_gv.PageIndex += 1;
break;
case "Last"://尾页
this.fkcx_gv.PageIndex = this.fkcx_gv.PageCount - 1;
break;
}
xianshi();
}
protected void fkcx_gv_DataBound(object sender, EventArgs e)
{
GridViewRow pagerRow = fkcx_gv.BottomPagerRow;
Label lblCurrent = (Label)pagerRow.Cells[0].FindControl("lblPageCurrent");//发生错误的地方
Label lblCount = (Label)pagerRow.Cells[0].FindControl("lblPageCount");
Label lblRow = (Label)pagerRow.Cells[0].FindControl("lblPageRow");
// 获取按钮实例,为了控制其是否可用
LinkButton btnFirstTem = (LinkButton)pagerRow.Cells[0].FindControl("btnFirst");
LinkButton btnPrevTem = (LinkButton)pagerRow.Cells[0].FindControl("btnPrev");
LinkButton btnNextTem = (LinkButton)pagerRow.Cells[0].FindControl("btnNext");
LinkButton btnLastTem = (LinkButton)pagerRow.Cells[0].FindControl("btnLast"); if (lblCurrent.Text != null)
lblCurrent.Text = (this.fkcx_gv.PageIndex + 1).ToString();
if (lblCount != null)
lblCount.Text = this.fkcx_gv.PageCount.ToString();
if (lblRow != null)
lblRow.Text = rowCount.ToString();
if (this.fkcx_gv.PageIndex == 0)
{
btnFirstTem.Enabled = false;
btnPrevTem.Enabled = false;
if (this.fkcx_gv.PageCount == 1)
{
btnNextTem.Enabled = false;
btnLastTem.Enabled = false;
}
}
else if (this.fkcx_gv.PageIndex == (this.fkcx_gv.PageCount - 1))
{
btnNextTem.Enabled = false;
btnLastTem.Enabled = false;
}
}
}
}
string sql1 = ""; int rowCount = 0; protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{ this.xianshi(); }
}
public SqlConnection GetConnection()
{
string myStr = ConfigurationManager.AppSettings["conn"].ToString();
SqlConnection myConn = new SqlConnection(myStr);
return myConn;
} private void xianshi()
{
SqlConnection myConn = GetConnection();
myConn.Open();
sql1 = this.fkcx_jj.Text;
string sqlStr = "select * from gg_gg,gg_zt where gg_gg.gg_fkzt=gg_zt.ggzt_id order by gg_zt.ggzt_mc";
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(sqlStr, myConn);
da.Fill(ds,"gg_gg");
rowCount = ds.Tables["gg_gg"].Rows.Count;
fkcx_gv.DataSource=ds.Tables["gg_gg"];
fkcx_gv.DataBind(); }
protected void NavigateToPage(object sender, CommandEventArgs e)
{
switch (e.CommandArgument.ToString())//控制转页
{
case "First"://首页
this.fkcx_gv.PageIndex = 0;
break;
case "Prev"://上一页
if (this.fkcx_gv.PageIndex > 0)
this.fkcx_gv.PageIndex -= 1;
break;
case "Next"://下一页
if (this.fkcx_gv.PageIndex < (this.fkcx_gv.PageCount - 1))
this.fkcx_gv.PageIndex += 1;
break;
case "Last"://尾页
this.fkcx_gv.PageIndex = this.fkcx_gv.PageCount - 1;
break;
}
xianshi();
}
protected void fkcx_gv_DataBound(object sender, EventArgs e)
{
GridViewRow pagerRow = fkcx_gv.BottomPagerRow;
Label lblCurrent = (Label)pagerRow.Cells[0].FindControl("lblPageCurrent");//发生错误的地方
Label lblCount = (Label)pagerRow.Cells[0].FindControl("lblPageCount");
Label lblRow = (Label)pagerRow.Cells[0].FindControl("lblPageRow");
// 获取按钮实例,为了控制其是否可用
LinkButton btnFirstTem = (LinkButton)pagerRow.Cells[0].FindControl("btnFirst");
LinkButton btnPrevTem = (LinkButton)pagerRow.Cells[0].FindControl("btnPrev");
LinkButton btnNextTem = (LinkButton)pagerRow.Cells[0].FindControl("btnNext");
LinkButton btnLastTem = (LinkButton)pagerRow.Cells[0].FindControl("btnLast"); if (lblCurrent.Text != null)
lblCurrent.Text = (this.fkcx_gv.PageIndex + 1).ToString();
if (lblCount != null)
lblCount.Text = this.fkcx_gv.PageCount.ToString();
if (lblRow != null)
lblRow.Text = rowCount.ToString();
if (this.fkcx_gv.PageIndex == 0)
{
btnFirstTem.Enabled = false;
btnPrevTem.Enabled = false;
if (this.fkcx_gv.PageCount == 1)
{
btnNextTem.Enabled = false;
btnLastTem.Enabled = false;
}
}
else if (this.fkcx_gv.PageIndex == (this.fkcx_gv.PageCount - 1))
{
btnNextTem.Enabled = false;
btnLastTem.Enabled = false;
}
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货