Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- WebMethod
- ===========================================================
- [WebMethod, ScriptMethod]
- public static List<RecentNews> GetDailyNews()
- {
- List<RecentNews> RecentNewsList = new List<RecentNews>();
- try
- {
- SqlCommand comRecentNews = new SqlCommand("SP_GetRecentNews", conDB);
- comRecentNews.CommandType = CommandType.StoredProcedure;
- if (conDB.State == ConnectionState.Closed)
- conDB.Open();
- SqlDataReader rdr = comRecentNews.ExecuteReader();
- DataTable dt = new DataTable();
- dt.Load(rdr);
- foreach (DataRow r in dt.Rows)
- {
- RecentNewsList.Add(new RecentNews
- {
- Id = (int)r["Id"],
- Subject = r["Subject"].ToString(),
- Line1 = r["Line1"].ToString(),
- Line2 = r["Line2"].ToString(),
- Line3 = r["Line3"].ToString(),
- Line4 = r["Line4"].ToString(),
- Line5 = r["Line5"].ToString(),
- Line6 = r["Line6"].ToString(),
- Line7 = r["Line7"].ToString(),
- PublishDate = Convert.ToDateTime(r["PublishDate"]).Date
- });
- }
- }
- catch (Exception ee)
- {
- }
- finally
- {
- conDB.Close();
- }
- return RecentNewsList;
- }
- AJAX CALL
- ======================================================
- <script>
- $(function () {
- LoadRecentNews();
- });
- function LoadRecentNews() {
- var url = '<%= ResolveUrl("/WebMethods.aspx/GetDailyNews") %>';
- $.ajax({
- url: url,
- type: "POST",
- dataType: "json",
- contentType: "application/json; charset=utf-8",
- success: function (Result) {
- $.each(Result.d, function (key, value) {
- var html = "<h1>" + value.Subject + "</h1>";
- $("#subjectline").append(html);
- $("#Line1").append(value.Line1);
- $("#Line2").append(value.Line2);
- $("#Line3").append(value.Line3);
- $("#Line4").append(value.Line4);
- $("#Line5").append(value.Line5);
- $("#Line6").append(value.Line6);
- $("#Line7").append(value.Line7);
- });
- },
- error: function (e, x) {
- alert(x.ResponseText);
- }
- });
- }
- function forgotpassword()
- {
- window.location.href = 'ForgotPassword.aspx';
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement