大家好我正在使用转发器将我的数据保存到我的数据库但是我遇到了问题,第一个是转发器的按钮正在触发而另一个不能有人帮忙吗?请您检查一下,然后为什么其他按钮没有被触发请感谢您的支持
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Bidding.aspx.vb" Inherits="Bidding" %>
<!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">
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="SM1" runat="server">
</asp:ScriptManager>
<asp:repeater id="Repeater1" runat="server">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li> <a href="ProductDetails.aspx?ItemID=<%# Eval("ItemID") %>"> <asp:Image id="Image1" runat="server" ImageUrl='<%#Eval("Image1") %>' /></a>
<div class="product-info">
<h3>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Name")%>'></asp:Label> </h3>
<div class="product-desc">
<h4>Bid</h4>
<asp:TextBox ID="txtbid" runat="server"></asp:TextBox><asp:Button ID="btnSave"
runat="server" Text="btnSave" />
<asp:HiddenField ID="HiddenField1" Value='<%#Eval("EndDate")%>' runat="server" />
<asp:Label ID="lblauction" Visible="false" Text='<%#Eval("AuctionID")%>' runat="server" />
<strong class="price"><%# Eval("Price")%></strong>
<br/> <p>
<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>
</div>
</p>
</div>
</div>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:repeater>
<asp:Timer ID="timer1" Interval="1000" OnTick="timer1_tick" runat ="server">
</asp:Timer>
<asp:HiddenField ID="HiddenItem" runat="server" />
</div>
</form>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="http://cdn.jsdelivr.net/json2/0.1/json2.js"></script>
<script type="text/javascript">
$(function () {
$("[id*=btnSave]").on("click", function () {
var user = {};
user.BiddingPrice = $("[id*=txtbid]").val();
user.AuctionID = $("[id*=lblauction]").val();
$.ajax({
type: "POST",
url: "Bidding.aspx/SaveUser",
data: '{user: ' + JSON.stringify(user) + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
alert("BID has been added successfully.");
window.location.reload();
}
});
return false;
});
});
</script>
</body>
</html>
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 Bidding
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
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Using con1 As New SqlConnection(_start)
Dim sql1 As String = "SELECT Item.ItemID, Item.Name,Item.Image1, Item.Description, Item.Price,Auction.EndDate,Auction.AuctionID FROM Item INNER JOIN Auction ON Item.ItemID = Auction.ItemID Where Auction.Status='Valid' AND Auction.EndDate>=@endate "
Dim myCommand1 As New SqlCommand(sql1, con1)
myCommand1.Parameters.AddWithValue("@endate", DateTime.Now)
myCommand1.CommandType = CommandType.Text
con1.Open()
Dim category As SqlDataReader
category = myCommand1.ExecuteReader()
'binding data from category table to ddlcategory
Repeater1.DataSource = category
Repeater1.DataBind()
End Using
End If
End Sub
<WebMethod()> _
<ScriptMethod()> _
Public Shared Sub SaveUser(ByVal user As BID)
Dim constr As String = ConfigurationManager.ConnectionStrings("VirgoPlaza").ConnectionString
Using con As New SqlConnection(constr)
Using cmd2 As New SqlCommand("Select BiddingPrice From Bid")
cmd2.CommandType = CommandType.Text
con.Open()
cmd2.Connection = con
Dim result As Double = cmd2.ExecuteScalar
Dim result2 As Integer = Convert.ToInt32(result)
Dim con1 As New SqlConnection(constr)
Dim auction1 As Integer = Convert.ToInt32(user.AuctionID)
If result2 = 0 Then
Using cmd As New SqlCommand("INSERT INTO BID VALUES(@Date, @BiddingPrice,@Status,@AuctionID,@BuyerID)")
cmd.CommandType = CommandType.Text
cmd.Parameters.AddWithValue("@Date", DateTime.Now)
cmd.Parameters.AddWithValue("@BiddingPrice", User.BiddingPrice)
cmd.Parameters.AddWithValue("@Status", "Available")
cmd.Parameters.AddWithValue("@AuctionID", auction1)
cmd.Parameters.AddWithValue("@BuyerID", 1)
cmd.Connection = con
con.Open()
cmd.ExecuteNonQuery()
con.Close()
End Using
Else
If result2 >= User.BiddingPrice Then
MsgBox("Bid should be greather")
Else
Dim finalbid As Double = result2
MsgBox(finalbid)
Using cmd As New SqlCommand("UPDATE BID SET Date =@Date,BiddingPrice= @BiddingPrice,Status=@Status,AuctionID=@AuctionID,BuyerID =@BuyerID")
cmd.CommandType = CommandType.Text
cmd.Parameters.AddWithValue("@Date", DateTime.Now)
cmd.Parameters.AddWithValue("@BiddingPrice", User.BiddingPrice)
cmd.Parameters.AddWithValue("@Status", "Available")
cmd.Parameters.AddWithValue("@AuctionID", 11)
cmd.Parameters.AddWithValue("@BuyerID", 1)
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
End Using
End If
End If
End Using
End Using
End Sub
Public Class BID
Public Property BiddingPrice As Integer
Get
Return _BiddingPrice
End Get
Set(ByVal value As Integer)
_BiddingPrice = value
End Set
End Property
Private _BiddingPrice As String
Public Property AuctionID As Integer
Get
Return _AuctionID
End Get
Set(ByVal value As Integer)
_AuctionID = value
End Set
End Property
Private _AuctionID As String
End Class
Protected Sub timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles timer1.Tick
For Each item As RepeaterItem In Repeater1.Items
Dim hidden = TryCast(item.FindControl("HiddenField1"), HiddenField)
If Not SM1.IsInAsyncPostBack Then
hidden.Value = hidden.Value
End If
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)
'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)
Dim result2 As Integer = TimeSpan.Compare(ts, travelTime)
If result2 >= 0 Then
Using con1 As New SqlConnection(_start)
Dim sql1 As String = "SELECT Item.ItemID FROM Item INNER JOIN Auction ON Item.ItemID = Auction.ItemID Where Auction.Status='Valid' AND Auction.EndDate<=@endate "
Dim cmd As New SqlCommand(sql1, con1)
con1.Open()
cmd.Parameters.AddWithValue("@endate", DateTime.Now)
Dim query As Integer = cmd.ExecuteScalar
''query = Convert.ToInt32(HiddenItem.Value).ToString look in finalcoursework
Response.Redirect("ShoppingCart.aspx?query=")
con1.Close()
End Using
End If
Next
End Sub
End Class