Fork me on GitHub

TimerControl应用

 

最近看了一些关于Atlas的文件,有些好东东,摘出来供大家分享。

原来的文章网址:http://atlas.asp.net/docs/atlas/doc/controls/default.aspx#aspnet

最后一个例子的源代码。

Aspx源码

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4" %>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

    <title>滚动刷新广告</title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

    <marquee bgcolor='aqua' style="height: 216px" direction="up" >

     <atlas:ScriptManager runat="server" ID="ScriptManager1" EnablePartialRendering="true" />

               <atlas:TimerControl runat="server" Interval="2000" ID="tickerTimer" OnTick="tickerTimer_Tick" />

            <atlas:UpdatePanel runat="server" ID="UpdatePanel1">

                <Triggers>

                    <atlas:ControlEventTrigger ControlID="tickerTimer" EventName="Tick" />

                </Triggers>

                <ContentTemplate>

                  

                        <asp:Label runat="server" ID="nameAAA" Text=" " Font-Bold="True" />

                        <asp:Label runat="server" ID="valueAAA" Text="" Font-Bold="True" />

                    &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;<asp:Label runat="server" ID="nameBBB" Text="" Font-Bold="True" />

                        <asp:Label runat="server" ID="valueBBB" Text="" Font-Bold="True" />

                    &nbsp; &nbsp; &nbsp; &nbsp;

                    <asp:Label runat="server" ID="nameCCC" Text="" Font-Bold="True" />

                        <asp:Label runat="server" ID="valueCCC" Text="" Font-Bold="True" />

               

                </ContentTemplate>

            </atlas:UpdatePanel>

    </marquee>

    </div>

    </form>

</body>

</html>

注:IntervalTimerControl的间隔时间属性,通过修改此值可改变刷新时间

CS源码

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

 

public partial class Default4 : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        if (!IsPostBack)

        {

            bd();

            ViewState["int"] = 0;

        }

    }

    protected void tickerTimer_Tick(object sender, EventArgs e)

    {

        bd();

    }

 

    protected void bd()

    {

        DataSet ds = new DataSet();

        ds.ReadXml(Request.PhysicalApplicationPath.ToString()+"SQLFile.xml");

        DataTable dt = ds.Tables[0];

        DataView dv= dt.DefaultView;

 

        if (Convert.ToInt32(ViewState["int"]) < dt.Rows.Count)

        {

            DataRowView dr = dv[0 + Convert.ToInt32(ViewState["int"])];

            nameAAA.Text = dr["mc"].ToString();

            valueAAA.Text = dr["SQL"].ToString();

 

            try

            {

                dr = dv[1 + Convert.ToInt32(ViewState["int"])];

                nameBBB.Text = dr["mc"].ToString();

                valueBBB.Text = dr["SQL"].ToString();

            }

            catch

            {

                nameBBB.Text = "";

                valueBBB.Text = "";

            }

            try

            {

                dr = dv[2 + Convert.ToInt32(ViewState["int"])];

                nameCCC.Text = dr["mc"].ToString();

                valueCCC.Text = dr["SQL"].ToString();

            }

            catch

            {

                nameCCC.Text = "";

                valueCCC.Text = "";           

            }

 

            ViewState["int"]= Convert.ToInt32(ViewState["int"])+ 3;

        }

        else

        {

            ViewState["int"] = 0;

        }

    }

}

注:tickerTimer_TickTimerControl的一个事件,为每间隔一段时间后向服务端触发的事件。

Xml文件

<?xml version="1.0" standalone="yes"?>

<NewDataSet>

 <Table>

    <mc>西瓜:</mc>

    <SQL>

      100

    </SQL>

 </Table>

 <Table>

    <mc>小瓜:</mc>

    <SQL>

     250

    </SQL>

 </Table>

 <Table>

    <mc>馒头:</mc>

    <SQL>

      125

    </SQL>

 </Table>

 <Table>

    <mc>豆角:</mc>

    <SQL>

      254

    </SQL>

 </Table>

 <Table>

    <mc>红豆:</mc>

    <SQL>

     75

    </SQL>

 </Table>

 <Table>

    <mc>红米:</mc>

    <SQL>

      75

    </SQL>

 </Table>

 <Table>

    <mc>大豆泥:</mc>

    <SQL>

      10075

    </SQL>

 </Table>

</NewDataSet>

注:这是我一个自己写的XML,可从数据库中读取。

 

上面的例子开发人员可根据自己的要求优化,仅作一下参考!

posted @ 2006-07-11 10:51  桂素伟  阅读(537)  评论(0编辑  收藏  举报