asp.net中数据列表中的时间倒计时 [英] time countdown in data list in asp.net

查看:79
本文介绍了asp.net中数据列表中的时间倒计时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!
我叫AZAD RATN.我正在尝试很长时间,但是没有发生.实际上,我在asp.net的数据列表中进行了倒计时.

数据列表中每个项目的日期都来自数据库.倒计时也发生了,但问题是它在一段时间内自动刷新.

我的代码是这样的:

hi!
My name is AZAD RATN. i am trying from a long time but its not happening.actually i time countdown in data list in asp.net.

date is coming from database for every items in datalist. it countdown happening also but the problem is it is auto refresh for a time gap.

my code is like this:

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
                   <ContentTemplate>





<div class="painting-desc1">
                                    <asp:Timer ID="tmrStopWatch" runat="server" Interval="1000" OnTick="Timer1_Tick">
                                    </asp:Timer>
                                    <asp:DataList ID="dlPainting" RepeatColumns="4" RepeatDirection="Horizontal" runat="server"

                                        OnItemCommand="dlPainting_ItemCommand" OnItemDataBound="dlPainting_ItemDataBound">
                                        <ItemTemplate>
 
                                                                                Countdown
                                                                            </td>
                                                                            <td>
                                                                                <asp:Label ID="watch" Visible="false" runat="server" Text='<%# Bind("close_date")%>'></asp:Label>
                                                                                <table width="100%" border="0" cellspacing="5" cellpadding="0">
                                                                                    <tr>
                                                                                        <td class="countdown" align="center">
                                                                                            <span class="cspan">Days</span><br />
                                                                                            <asp:Label ID="lblDAYS" runat="server" Text="00"></asp:Label>
                                                                                        </td>
                                                                                        <td class="countdown" align="center">
                                                                                            <span class="cspan">Hrs</span><br />
                                                                                            <asp:Label ID="lblHOURS" runat="server" Text="00"></asp:Label>
                                                                                        </td>
                                                                                        <td class="countdown" align="center">
                                                                                            <span class="cspan">Min</span><br />
                                                                                            <asp:Label ID="lblMINUTES" runat="server" Text="00"></asp:Label>
                                                                                        </td>
                                                                                        <td class="countdown" align="center">
                                                                                            <span class="cspan">Sec</span><br />
                                                                                            <asp:Label ID="lblSECONDS" runat="server" Text="00"></asp:Label>
                                                                                        </td>
                                                                                    </tr>
                                                                                </table>
                                                                            </td>
                                                                        </tr>
                                                                        <tr>
                                                                            <td>
                                                                                &nbsp;
                                                                            </td>
                                                                        </tr>
                                                                    </table>
                                                                </td>
                                                                <tr>
                                                                    <td class="bid-now-btn1">
                                                                        <asp:Label ID="lblPID" Visible="false" runat="server" Text='<%#Bind("painting_id") %>'></asp:Label>
                                                                        <asp:ImageButton ID="ibtnBidNow" CommandArgument='<%#Bind("painting_id") %>' CommandName="BidNow"

                                                                            ImageUrl="images/bid-now-btn.jpg" runat="server" />
                                                                    </td>
                                                                    <tr>
                                                                        <tr>
                                                                            <td class="highest-bidder-txt">
                                                                                <asp:Label ID="lblArtistID" Visible="false" runat="server" Text='<%#Bind("artist") %>'></asp:Label>
                                                                                <strong>
                                                                                    <asp:Label ID="lblBid_Count" runat="server" Text='<%#Bind("Bid_Count") %>'></asp:Label></strong>
                                                                                Bids<br />
                                                                                <strong>Going at</strong>
                                                                                <asp:Label ID="lblGoingPrice" runat="server" Text='<%#Bind("current_bid_price") %>'></asp:Label>
                                                                                <asp:Label ID="lblGoingPriceCOMP" runat="server" Visible="false" Text='<%#Bind("current_bid_price") %>'></asp:Label>
                                                                            </td>
                                                                        </tr>
                                                    </table>
                                                </div>
                                            </div>
                                        </ItemTemplate>
                                    </asp:DataList>
                                </div>

</ContentTemplate>
                    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="ddlF1Driver" EventName="SelectedIndexChanged" />
                        <asp:AsyncPostBackTrigger ControlID="ddlNGO" EventName="SelectedIndexChanged" />
                        <asp:AsyncPostBackTrigger ControlID="ddlSchool" EventName="SelectedIndexChanged" />
                        <asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />
                        <asp:AsyncPostBackTrigger ControlID="tmrStopWatch" EventName="Tick" />
                        <asp:AsyncPostBackTrigger ControlID="lbtnLogin" EventName="Click" />
                    </Triggers>
                </asp:UpdatePanel>
//****************************************************

&lt;u&gt;.aspx.cs file code like this..&lt;/u&gt;</pre>


protected void dlPainting_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
        {

            Label lblValue = (Label)e.Item.FindControl("lblReservePrice");
            Label currency = (Label)e.Item.FindControl("lblReservePrice");
            string ab;
            ab = lblValue.Text;
            Label lblClose_date = (Label)e.Item.FindControl("lblCloseDate");
            Label lblDAYS = (Label)e.Item.FindControl("lblDAYS");
            Label lblHOURS = (Label)e.Item.FindControl("lblHOURS");
            Label lblMINUTES = (Label)e.Item.FindControl("lblMINUTES");
            Label lblSECONDS = (Label)e.Item.FindControl("lblSECONDS");
            Label lblPID = (Label)e.Item.FindControl("lblPID");
            Label watch = (Label)e.Item.FindControl("watch");
            ImageButton Image1 = (ImageButton)e.Item.FindControl("Image1");
            SqlCommand cmd = new SqlCommand("select jaypeeauction.vtag.sname,f1driver.img,f1driver.id,jaypeeauction.vtag.nFriendid,jaypeeauction.vtag.coords from f1driver,jaypeeauction.vtag where f1driver.id=jaypeeauction.vtag.nFriendid and jaypeeauction.vtag.nPhotoId='" + lblPID.Text + "'", con);
            //con.Open();
            SqlDataReader dr = cmd.ExecuteReader();
            for (int i = -1; i < dlPainting.Items.Count; i++)

            {



                while (dr.Read())

                {

                    string string1 = dr["sname"].ToString();

                    tagName = tagName + string1 + ", ";

                    Image1.ToolTip = tagName;

                }

                tagName = "";

            }

            cmd.Dispose();

            dr.Close();

            //con.Close();

            DateTime close_date = Convert.ToDateTime(watch.Text);

            DateTime today = DateTime.Now;

            TimeSpan ts = close_date - today;

            lblDAYS.Text = ts.Days.ToString();

            lblHOURS.Text = ts.Hours.ToString();

            lblMINUTES.Text = ts.Minutes.ToString();

            lblSECONDS.Text = ts.Seconds.ToString();

            dlPainting.DataBind();



        }







    }

推荐答案

A quick look at the code shows that you are using the timer to refresh the page after every 1000 milliseconds. This way the user will not be able to view the page if it keeps on refreshing.

The better way will be to use the client side javascript to display the count down

Use a hidden field on the page and assign it the time in the Page_Load event. Then display the timer in javascript as

A quick look at the code shows that you are using the timer to refresh the page after every 1000 milliseconds. This way the user will not be able to view the page if it keeps on refreshing.

The better way will be to use the client side javascript to display the count down

Use a hidden field on the page and assign it the time in the Page_Load event. Then display the timer in javascript as

<script type="text/javascript">
<!--
var currentTime = hiddenField1.value;
var hours = currentTime.getHours()
var minutes = currentTime.getMinutes()
if (minutes < 10){
minutes = "0" + minutes
}
document.write(hours + ":" + minutes + " ")
if(hours > 11){
document.write("PM")
} else {
document.write("AM")
}
//-->
</script>


as per above you want to refresh the page after 1000 milliseconds.
you may use below tag in the page directive.



it will refresh the page after 1000 milliseconds.
correct me if I am wrong.
as per above you want to refresh the page after 1000 milliseconds.
you may use below tag in the page directive.



it will refresh the page after 1000 milliseconds.
correct me if I am wrong.


这篇关于asp.net中数据列表中的时间倒计时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆