开发学院网页设计JavaScript 使用jQuery, CSS, JSON 和ASP.NET打造一个新闻轮换... 阅读

使用jQuery, CSS, JSON 和ASP.NET打造一个新闻轮换控件

 2010-01-08 00:00:00 来源:WEB开发网   
核心提示: 在服务器端,我们像下面这样去实现:代码protectedvoidPage_Load(objectsender,EventArgse){//***RoutetothePagelevelcallback'handler'this.HandleCallbacks();}//Callba

在服务器端,我们像下面这样去实现:

代码

    protected void Page_Load(object sender, EventArgs e)
    {
        // *** Route to the Page level callback 'handler'
        this.HandleCallbacks();
    }
    // Callback routing
    public void HandleCallbacks()
    {
        if (string.IsNullOrEmpty(Request.Params["Callback"]))
            return;
        // *** We have an action try and match it to a handler
        switch (Request.Params["Callback"])
        {
            case "fetchAllNews":
                this.FetchAllNews();
                break;
        }
        Response.StatusCode = 500;
        Response.Write("Invalid Callback Method");
        Response.End();
    }
    public void FetchAllNews()
    {
        List<NewsItem> lsttst = new List<NewsItem>();
        lsttst.Add(new NewsItem("Environment of Australia", 
        this.ResolveUrl("~/img/news1.jpg"), 
        this.ResolveUrl("~/img/news1_thumb.jpg"), 
        "Australia has a rich variety of endemic legume 
        species that thrive in nutrient-poor soils because 
        of their symbiosis with rhizobia bacteria and mycorrhizal fungi",
        DateTime.Now.ToShortDateString()));
        lsttst.Add(new NewsItem("Economy of Australia", 
        this.ResolveUrl("~/img/news2.jpg"), 
        this.ResolveUrl("~/img/news2_thumb.jpg"), 
        "The Australian dollar is the currency of the 
        Commonwealth of Australia, including Christmas Island, 
        Cocos (Keeling) Islands, and Norfolk Island", 
        DateTime.Now.ToShortDateString()));
        lsttst.Add(new NewsItem("Demographics of Australia and 
        Immigration to Australia", this.ResolveUrl("~/img/news3.jpg"), 
        this.ResolveUrl("~/img/news3_thumb.jpg"), 
        "Most of the estimated 21.8 million Australians are 
        descended from colonial-era settlers and post-Federation 
        immigrants from Europe", DateTime.Now.ToShortDateString()));
        lsttst.Add(new NewsItem("Religion in Australia", 
        this.ResolveUrl("~/img/news4.jpg"), 
        this.ResolveUrl("~/img/news4_thumb.jpg"), 
        "Australia has no state religion. In the 2006 census, 
        64% of Australians were listed as Christian of 
        any denomination, including 26% as Roman Catholic and 
        19% as Anglican", DateTime.Now.ToShortDateString()));
        lsttst.Add(new NewsItem("Education in Australia", 
        this.ResolveUrl("~/img/news5.jpg"), 
        this.ResolveUrl("~/img/news5_thumb.jpg"), 
        "School attendance is compulsory throughout Australia. 
        In most Australian States at 5–6 years of age all children 
        receive 11 years of compulsory education", 
        DateTime.Now.ToShortDateString()));
        Response.ContentType = "application/json; charset=utf-8";
        Response.Write(JavaScriptConvert.SerializeObject(lsttst));
        Response.End();
    }

参考原文:http://www.codeproject.com/KB/applications/TopNews.aspx

雅虎新闻轮换控件:http://www.codeproject.com/KB/applications/YahooNewsRotator_.aspx

出处:http://zhuqil.cnblogs.com

本文示例源代码或素材下载

上一页  1 2 3 4 

Tags:使用 jQuery CSS

编辑录入:爽爽 [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接