Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. WebMethod
  2. ===========================================================
  3. [WebMethod, ScriptMethod]
  4. public static List<RecentNews> GetDailyNews()
  5. {
  6. List<RecentNews> RecentNewsList = new List<RecentNews>();
  7. try
  8. {
  9. SqlCommand comRecentNews = new SqlCommand("SP_GetRecentNews", conDB);
  10. comRecentNews.CommandType = CommandType.StoredProcedure;
  11. if (conDB.State == ConnectionState.Closed)
  12. conDB.Open();
  13.  
  14. SqlDataReader rdr = comRecentNews.ExecuteReader();
  15. DataTable dt = new DataTable();
  16. dt.Load(rdr);
  17. foreach (DataRow r in dt.Rows)
  18. {
  19. RecentNewsList.Add(new RecentNews
  20. {
  21. Id = (int)r["Id"],
  22. Subject = r["Subject"].ToString(),
  23. Line1 = r["Line1"].ToString(),
  24. Line2 = r["Line2"].ToString(),
  25. Line3 = r["Line3"].ToString(),
  26. Line4 = r["Line4"].ToString(),
  27. Line5 = r["Line5"].ToString(),
  28. Line6 = r["Line6"].ToString(),
  29. Line7 = r["Line7"].ToString(),
  30. PublishDate = Convert.ToDateTime(r["PublishDate"]).Date
  31.  
  32. });
  33. }
  34.  
  35. }
  36. catch (Exception ee)
  37. {
  38. }
  39. finally
  40. {
  41. conDB.Close();
  42. }
  43. return RecentNewsList;
  44. }
  45.  
  46.  
  47. AJAX CALL
  48. ======================================================
  49. <script>
  50. $(function () {
  51. LoadRecentNews();
  52. });
  53.  
  54.  
  55. function LoadRecentNews() {
  56.  
  57. var url = '<%= ResolveUrl("/WebMethods.aspx/GetDailyNews") %>';
  58.  
  59. $.ajax({
  60. url: url,
  61. type: "POST",
  62. dataType: "json",
  63. contentType: "application/json; charset=utf-8",
  64. success: function (Result) {
  65. $.each(Result.d, function (key, value) {
  66.  
  67. var html = "<h1>" + value.Subject + "</h1>";
  68. $("#subjectline").append(html);
  69. $("#Line1").append(value.Line1);
  70. $("#Line2").append(value.Line2);
  71. $("#Line3").append(value.Line3);
  72. $("#Line4").append(value.Line4);
  73. $("#Line5").append(value.Line5);
  74. $("#Line6").append(value.Line6);
  75. $("#Line7").append(value.Line7);
  76. });
  77.  
  78. },
  79.  
  80.  
  81. error: function (e, x) {
  82. alert(x.ResponseText);
  83. }
  84. });
  85. }
  86.  
  87. function forgotpassword()
  88. {
  89. window.location.href = 'ForgotPassword.aspx';
  90. }
  91. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement