⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 default.aspx.cs

📁 Asynchrounous pages with Ajax to refresh the page without postback
💻 CS
字号:
using System;
using System.Data;
using System.Web;
using System.Web.Services;
using System.Web.UI;

public partial class _Default : Page 
{
protected void Page_Load(object sender, EventArgs e)
{
  // If no data has been cached yet, generate
  //  test data for purposes of demonstration.
  //
  // In actual use, this should cache data
  //  from your database or other live source.
  if (Cache["Headlines"] == null)
  {
    // Create a DataTable.
    DataTable dt = new DataTable("Headlines");

    // Add schema for the article example.
    dt.Columns.Add("Date", typeof(DateTime));
    dt.Columns.Add("Title", typeof(string));

    // Populate the test data.
    dt.Rows.Add(new object[] {DateTime.Now, 
       "CSS style as AJAX progress indicator"});
    dt.Rows.Add(new object[] {DateTime.Now.AddDays(-1.25), 
       "AJAX, file downloads, and IFRAMEs"});
    dt.Rows.Add(new object[] {DateTime.Now.AddDays(-2), 
       "Easily refresh an UpdatePanel, using JavaScript" });

    // Cache the initialized DataTable.
    Cache["Headlines"] = dt;
  }
}

[WebMethod]
public static long GetLatestHeadlineTick()
{
  // Retrieve the cached DataTable.
  DataTable dt = (DataTable)HttpContext.Current.Cache["Headlines"];

  // Sort by date and find the latest article.
  DataRow row = dt.Select("", "Date DESC")[0];

  // Return that article's timestamp, in ticks.
  return ((DateTime)row["Date"]).Ticks;
}

protected void up1_Load(object sender, EventArgs e)
{
  // Retrieve the cached DataTable.
  DataTable dt = (DataTable)Cache["Headlines"];

  // Set the hidden field's value to the
  //  latest headline's "tick".
  LatestDisplayTick.Value = GetLatestHeadlineTick().ToString();

  Headlines.DataSource = dt;
  Headlines.DataBind();
}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -