1 protected void updown() 2 { 3 int id = Convert.ToInt32(Request.QueryString["id"].ToString()); 4 string sqlUp = string.Format("select top 1 title, max(id) as id from blog where id<'{0}' group by title order by id desc",id); 5 string sqlDown = string.Format("select top 1 title, min(id) as id from blog where id>'{0}' group by title order by id asc",id); 6 SqlConnection con = DataBase.createCon(); 7 con.Open(); 8 SqlCommand cmdUp = new SqlCommand(sqlUp,con); 9 SqlDataReader drUp = cmdUp.ExecuteReader(); 10 if (drUp.Read()) 11 { 12 hyperUp.Text = drUp["title"].ToString(); 13 hyperUp.NavigateUrl = "~/BlogView.aspx?id="+drUp["id"].ToString(); 14 } 15 else 16 { 17 hyperUp.Text = "没有了"; 18 } 19 cmdUp.Dispose(); 20 drUp.Close(); 21 SqlCommand cmdDown = new SqlCommand(sqlDown, con); 22 SqlDataReader drDown = cmdDown.ExecuteReader(); 23 if (drDown.Read()) 24 { 25 hyperDown.Text = drDown["title"].ToString(); 26 hyperDown.NavigateUrl = "~/BlogView.aspx?id=" + drDown["id"].ToString(); 27 } 28 else 29 { 30 hyperDown.Text = "没有了"; 31 } 32 cmdDown.Dispose(); 33 drDown.Close(); 34 con.Close(); 35 }