Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

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


XML
<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();

        }



    }
Posted

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

JavaScript
<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>
 
Share this answer
 
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900