【问题标题】:How do you reference data from different formview (ASP.NET)你如何引用来自不同表单视图(ASP.NET)的数据
【发布时间】:2018-11-28 09:48:23
【问题描述】:

我对整个创建网站还是个新手,请理解并简单地解释一下。

好的,所以有一个名为 FormView1 的表单视图和另一个名为 User 的表单视图。在 FormView1 中,我有一个名为 CoinEarn 的数据和另一个名为 CurrentCoin 的 formview 数据(来自不同的 formview)

我想通过会话更新 CurrentCoin,以便在单击按钮(放置在 FormView1 模板内)后将其放在我的更新 SQL 中(通过 Session("CurrentCoin") = CurrentCoin + CoinEarn)。在代码中,我将按钮命名为“完成”。

由于 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

【问题讨论】:

    标签: sql asp.net visual-studio formview


    【解决方案1】:

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

    Session("CurrentcoinSession") = Coin + Session("CurrentCoin")

    get values from a form view

    【讨论】:

    • 感谢您的宝贵时间。我现在开始工作了。其实没那么糟,只是别人帮我写了那段代码,所以我只看懂了一半?。但是“从表单视图中获取值”帮助我现在完全理解它:)
    猜你喜欢
    • 2011-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多