新闻中显示上一篇下一篇

1.后台程序

public string strTitle;
  public string strAuthor;
  public string strContent;
  public string strNext;
  public string strId;
  public string strPreId;
  public string strPreTitle;
  public int intMin;
  private void Page_Load(object sender, System.EventArgs e)
  {
   if(!Page.IsPostBack)
   {
    BindData();
    Pre();
    next(); 
    min();
    
   }


   // 在此处放置用户代码以初始化页面
  }

  public void BindData()
  {
   SqlConnection sqlCon=DBCon.sqlCon1();
   SqlCommand sqlCmd=new SqlCommand("select * from news where new_type=1 and new_id='"+Request["id"]+"'",sqlCon);
   sqlCon.Open();
   SqlDataReader dr=sqlCmd.ExecuteReader();
   if(dr.Read())
   { 
    strTitle=dr["New_Title"].ToString();
    strAuthor=dr["New_Author"].ToString();
    strContent=dr["New_Content"].ToString();
    if(Convert.ToInt32(strPreId)==intMin)
    {
     Response.Write("djfkejfie");
    } 
    
   }
   sqlCon.Close();
  }

  public void min()
  {
   SqlConnection sqlCon=DBCon.sqlCon1();
   sqlCon.Open();
   SqlCommand sqlCmd=new SqlCommand("select min(New_Id) aa from news where new_type=1",sqlCon);
   SqlDataReader dr=sqlCmd.ExecuteReader();
   if(dr.Read())
   {
    intMin=Convert.ToInt32(dr["aa"]);
    Response.Write(intMin.ToString());
   }  
   

   sqlCmd.Dispose();
   sqlCon.Close();
  }
  public void next()
  {
   SqlConnection sqlCon=DBCon.sqlCon1();
   sqlCon.Open();
   SqlCommand sqlCmd1=new SqlCommand("select top 1 new_title,new_id from  news where new_type=1 and new_id>'"+Request["id"]+"'",sqlCon);
   SqlDataReader dr1=sqlCmd1.ExecuteReader();
   if(dr1.Read())
   {
    strNext=dr1["new_title"].ToString();
    strId=dr1["new_id"].ToString();

   }


   sqlCmd1.Dispose();
   sqlCon.Close();
  }

  public void Pre()
  {
   SqlConnection sqlCon=DBCon.sqlCon1();
   sqlCon.Open();
   SqlCommand sqlCmdPre=new SqlCommand("select top 1 new_title,new_id from news where new_id<'"+Request["id"]+"' order by new_Id desc",sqlCon);
   SqlDataReader drPre=sqlCmdPre.ExecuteReader();    
   while(drPre.Read())
   { 
    
    strPreId=drPre["new_id"].ToString();
    strPreTitle=drPre["new_title"].ToString();    
    if(strPreTitle=="")
    {
     strPreTitle="没有记录";
    }
    else
     strPreTitle=strPreTitle;
   }

   sqlCmdPre.Dispose();
   sqlCon.Close();

  }

 

2.前台代码

      下一篇:<a herf=show_new.aspx?id=<%=strId%>><%strNext%></a>

上一篇::<a herf=show_new.aspx?id=<%=strPreId>><%strPreTitle%></a>    

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值