Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

How to bind data to repeater without postback

$
0
0

so i have created a repeater, which display duration of each product, now i want that the when a duration finish, it remove the item without postback can someone help please

here are my code

Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Net.Mail
Imports System.Web.Configuration
Imports System.Web.Script.Services
Imports System.Web.Services
Partial Class Test
    Inherits System.Web.UI.Page
    Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("VirgoPlaza").ToString())
    Dim EndDate As DateTime
    Dim auction As Integer

    Private ReadOnly _start As String
    Public Sub New()
        _start = WebConfigurationManager.ConnectionStrings("VirgoPlaza").ConnectionString
    End Sub
    Public Function GenerateURL(ByVal Auction As Object) As String

        'Create URL for each product link
        Dim strProdUrl As String = "Wishlist.aspx?Pid=" & Auction

        Return strProdUrl
    End Function
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            BindItems()
        End If

    End Sub
    Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs)
        '--this method will fetch the end date from repeater item label and update the duration
        UpdateDuration()
    End Sub
    Private Sub UpdateDuration()
        For Each item As RepeaterItem In repItems.Items

            Dim hidden = TryCast(item.FindControl("HiddenField1"), HiddenField)

            Dim label2 = TryCast(item.FindControl("lblTimer"), Label)
            'Grab your DateTime object (checking that it exists)'

            'Store your TimeSpan Difference'
            Dim ts = (DateTime.Now - DateTime.Parse(hidden.Value))
            Dim travelTime As New TimeSpan(0, 0, 0, 0)
            Dim result2 As Integer = TimeSpan.Compare(ts, travelTime)
            If result2 <= 0 Then

                'Now you can output your time as you please (excluding any decimal points)'
                label2.Text = String.Format("Time Left: {0:dd\:hh\:mm\:ss}", ts)
                label2.Text = String.Format("{0:dd\:hh\:mm\:ss}", ts)
                label2.Text = Replace(label2.Text, ":", " Days ", , 1)
                label2.Text = Replace(label2.Text, ":", " Hours ", , 1)
                label2.Text = Replace(label2.Text, ":", " Mins ", , 1)
                label2.Text = Replace(label2.Text, ":", " Sec ", , 1)


            Else

                timer1.Enabled = True
                BindItems()
               






            End If
        Next
    End Sub
    Private Sub BindItems()
        Using con1 As New SqlConnection(_start)


            Dim sql1 As String = "[StoredProcedure2]"

            Dim myCommand1 As New SqlCommand(sql1, con1)
            myCommand1.CommandType = CommandType.StoredProcedure
            myCommand1.Parameters.AddWithValue("@endate", DateTime.Now)



            con1.Open()

            Dim category As SqlDataReader
            category = myCommand1.ExecuteReader()

            'binding data from category table to ddlcategory
            repItems.DataSource = category
            repItems.DataBind()

        End Using
<%@ Page Title="" Language="VB" MasterPageFile="~/Part1/MasterPage.master" AutoEventWireup="false" CodeFile="Test.aspx.vb" Inherits="Test" %><asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"></asp:Content><asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"><asp:ScriptManager ID="ScriptManager1" runat="server" /><asp:repeater id="repItems"  runat="server"><HeaderTemplate><ul></HeaderTemplate><ItemTemplate><li><center> <a href="../ProductDetails/ProductDetailOffline.aspx?ItemID=<%# Eval("ItemID") %>"> <asp:Image id="Image1" runat="server" ImageUrl='<%# Eval("Image")%>' /></a></center><div class="product-info"><h3><asp:Label ID="Label1" runat="server" Text='<%# Eval("Name")%>'></asp:Label> </h3><div class="product-desc"><table width="200px" border="0"><tr><td align="center" style="background-color:#7F7F7F; color:White;">Price</td></tr><tr><td align="center">Rs.&nbsp;<asp:Label ID="Label4" Text='<%#String.Format("{0:###,###.00}", Eval("CurrencyValuePost"))%>' runat="server" Font-Bold="true" /></td></tr><tr><td align="center"  style="background-color:#7F7F7F; color:White;">
                            Time Left</td></tr><tr><td align="center"><asp:UpdatePanel id="updPnl" runat="server" UpdateMode="Conditional"><ContentTemplate><asp:Label ID="lblTimer"   runat="server"></asp:Label></ContentTemplate><triggers><asp:asyncpostbacktrigger ControlID="timer1" eventname="tick" /></triggers></asp:UpdatePanel></td></tr></table><asp:Label ID="lblauction" Visible="false" Text='<%#Eval("AuctionID")%>' runat="server" /><asp:Label ID="lblEndDate" Visible="false" Text='<%#Eval("EndDate")%>' runat="server" /><asp:HiddenField ID="HiddenField1" Value='<%#Eval("EndDate")%>' runat="server" /><a href='<%#GenerateURL(Eval("AuctionID"))%>' style="border: 0 none white"><br/> <p></a></li></ItemTemplate><FooterTemplate></ul></FooterTemplate></asp:repeater><asp:UpdatePanel ID="UpdatePanel1" runat="server"><ContentTemplate><asp:Timer ID="timer1" Interval="1000" Enabled="true" OnTick="timer1_tick" runat ="server"></asp:Timer></ContentTemplate></asp:UpdatePanel></asp:Content><asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server"></asp:Content>




Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>