小妹,有一投票问题想请教。
简单叙述下工作流程:
此页由首也default.aspx通过<form id="vote" method="post" action="vote.aspx" target="_blank">跳转过来。
If 先判断拥护是否选择投票项目。Then
If 在判断用户是否已经投票了 Then
没有投票,则修改数据
session("tag") = 0
Else
提示用户已经投票完毕,不可重复投票
End If
Else
如果为选择则不修改数据库数据。
End If
存在问题:数据已经修改,但是页面上无法即刻显示修改后的结果。
我手动刷新后才会显示修改后结果。但是此时页面显示的message.text 已经为“对不起,您已经投过票!!!“
请大家帮忙!
代码如下:
Sub Page_Load(sender As Object, e As EventArgs)
'-------------------计算总票数---------------
MyConnection = New SqlConnection(dbconn)
SelectStr = "select sum(pvr_result) as result from play_voteResult"
SelectCmd = New SqlCommand(SelectStr,MyConnection)
MyConnection.Open()
readData = SelectCmd.ExecuteReader()
If readData.Read() Then
result = readData("result")
Else
Response.Write("没有数据")
End If
MyConnection.Close()
'---------------------------------
Response.Write(Session("tag"))
'If Not IsPostBack Then
If Request.Form("vote") <> "" Then
If Session("tag") <> 1 Then
Session("tag") = 0
'---------------------------------
Response.Write("可修改")
'修改投票数
MyConnection1 = New SqlConnection(dbconn)
UpdateStr = "UPDATE play_voteResult SET pvr_result=pvr_result+1 WHERE pvr_pvi_id = " + Request.Params("vote")
UpdateCmd = New SqlCommand(UpdateStr,MyConnection1)
MyConnection1.Open()
Try
UpdateCmd.ExecuteNonQuery()
Message.Text = "<font color=green size=2><b>感谢您的支持!!!</b></font>"
BindGrid()
Catch Exp As SQLException
MyConnection.Close()
End Try
MyConnection1.Close()
Else
Response.Write("禁止修改")
Message.Text = "<font color=#FF0000 size=2><b>对不起,您已经投过票!!!</b></font>"
End If
Else
Message.Text = "<font color=#FF0000 size=2><b>对不起,您还没有选择!!!</b></font>"
Session("tag") = 0
End If
'End If
BindGrid()
End Sub
Sub BindGrid()
MyConnection1 = New SqlConnection(dbconn)
ResultStr = "SELECT * FROM play_voteResult,play_voteItem WHERE play_voteResult.pvr_pvi_id = play_voteItem.pvi_id"
ResultCmd = New SqlDataAdapter(ResultStr,MyConnection1)
DS = New DataSet()
ResultCmd.Fill(DS,"results")
ResultDataGrid.DataSource = DS.Tables("results").DefaultView
'vote.DataSource = DS1.Tables("vitems").DefaultView
ResultDataGrid.DataBind()
End Sub
</script>