上一篇文章,下一篇文章,搞不出来.
网上找的一个方法,试了下不行的.
出来的结果,源代码: <a href=''></a>
news.aspx:
上一篇:<a href='<%# preurl %>'><%# pretitle %></a>
//上一篇,下一篇 protected void pre_next() { int now_id; try { now_id = Convert.ToInt32(Request.QueryString["id"].ToString()); } catch { now_id = 0; } string pre_Sql = "select top 1 title,max(id) from news where id < now_id"; string next_Sql = "select top 1 title,min(id) from news where id > now_id"; cn.Open(); SqlCommand cmd1 = new SqlCommand(pre_Sql, cn); SqlDataReader sdr1 = cmd1.ExecuteReader(); if (sdr1.Read()) { pretitle = sdr1["title"].ToString().Trim(); preurl = "Article.aspx?id=" + sdr1["id"].ToString() + " "; } else { pretitle = "第一篇了。"; } cmd1.Dispose(); sdr1.Close(); SqlCommand cmd2 = new SqlCommand(next_Sql, cn); SqlDataReader sdr2 = cmd2.ExecuteReader(); if (sdr2.Read()) { nexttitle = sdr2["title"].ToString().Trim(); nexturl = "Article.aspx?id=" + sdr2["id"].ToString() + " "; } else { nexttitle = "最后一篇了"; } sdr2.Close(); cmd2.Dispose(); cn.Close(); }