新闻中显示上一篇下一篇

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>

   
阅读更多
文章标签: string object
个人分类: ASP.NET
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

新闻中显示上一篇下一篇

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭