关闭

新闻中显示上一篇下一篇

713人阅读 评论(0) 收藏 举报

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>    

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:31219次
    • 积分:432
    • 等级:
    • 排名:千里之外
    • 原创:10篇
    • 转载:10篇
    • 译文:0篇
    • 评论:2条
    文章分类
    文章存档