如何引用来自不同FormView(ASP.NET)的数据

时间:2018-06-19 12:18:04

标签: sql asp.net visual-studio formview

我对创建网站还是一个陌生的角色,请简单地理解和解释。

好,因此有一个名为FormView1的formview和另一个名为User的formview。在FormView1中,我有一个名为CoinEarn的数据,另一个名为CurrentCoin的formview数据(来自不同的formview)

我想通过一个会话更新CurrentCoin,因此可以在单击按钮(位于FormView1模板内)后将其放在更新SQL上(通过Session(“ CurrentCoin”)= CurrentCoin + CoinEarn)。在代码中,我给按钮指定了命令名称“ complete”。

由于CurrentCoin来自不同的SQL和Formview,因此我需要引用/调用特定数据(CurrentCoin),以便进行会话。

我不确定我对此问题的想法/解决方案是否正确(通过调用数据或进行会话以更新CurrentCoin),但主要目的是在单击按钮后使CurrentCoin + = CoinEarn。

请帮助我!我一直在寻找答案,但是它太复杂了,无法在适当的网站中理解。

Protected Sub FormView1_ItemCommand(sender As Object, e As FormViewCommandEventArgs) Handles FormView1.ItemCommand
    If e.CommandName = "complete" Then


        Dim row As FormViewRow = FormView1.Row

        Dim TaskstatusLabel As Label = CType(row.FindControl("TaskStatusLabel"), Label)
        Dim what As String = TaskstatusLabel.Text

        Dim TaskCoin As Label = CType(row.FindControl("CoinEarnLabel"), Label)
        Dim Coin As String = TaskCoin.Text


        ''Session("CurrentcoinSession") = Coin + CurrentCoin 
        Dim TaskstatusLabelID As Label = CType(row.FindControl("TaskIDLabel"), Label)
        Dim whatTaskID As String = TaskstatusLabelID.Text
        Session("TaskIDSession") = whatTaskID

        If TaskstatusLabel.Text = "Complete" Then
            Session("TaskStatusSession") = "Incomplete"
            ElseIf TaskstatusLabel.Text = "Incomplete" Then
                Session("TaskStatusSession") = "Complete"
        End If

        SqlDsStatus1.Update()     
        FormView1.DataBind()

    End If

End Sub

1 个答案:

答案 0 :(得分:0)

使用会话CurrentCoin可选: Session(“ CurrentCoin”)=((Label)MyFormView.FindControl(“ lblCurrentCoin”))。Text

Session(“ CurrentcoinSession”)=币+ Session(“ CurrentCoin”)

get values from a form view