ASP.NET,VB:如何访问从后面code一个FormView控件里面? [英] ASP.NET, VB: how to access controls inside a FormView from the code behind?

查看:172
本文介绍了ASP.NET,VB:如何访问从后面code一个FormView控件里面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个复选框和FormView控件内部的面板,我需要从code访问他们身后,才能使用复选框来确定面板是否可见。这是我原来使用code,但因为我把FormView控件内部的控件,它不再工作。

I have a checkbox and a panel inside of a FormView control, and I need to access them from the code behind in order to use the checkbox to determine whether or not the panel is visible. This is the code that I originally used, but since I put the controls inside of the FormView, it no longer works.

Protected Sub checkGenEd_CheckedChanged(ByVal sender As Object, _
                                         ByVal e As System.EventArgs)
    If checkGenEd.Checked = True Then
        panelOutcome.Visible = True
    Else
        panelOutcome.Visible = False
    End If
End Sub 

我已经开始根据我抬起头,就在这里等问题,想出解决办法,但他们都是在C#中,而不是VB,所以这是据我得到的答案:

I've started to figure this out based on other questions I looked up on here, but all of them were in C# instead of VB, so this is as far as I got:

Protected Sub FormView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.DataBound
    If FormView1.CurrentMode = FormViewMode.Edit Then

    End If
End Sub

所以,是的,我不知道究竟是如何完成它。对不起,这可能是pretty基本的,但我在这是新的任何帮助将是AP preciated!

So yeah I'm not sure exactly how to finish it. I'm sorry, this might be pretty basic, but I'm new at this and any help would be appreciated!

编辑:这是我的code现在:

here's my code now:

Protected Sub FormView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.DataBound
    If FormView1.CurrentMode = FormViewMode.Edit Then

        CheckBox checkGenEd = formview1.FindControl("checkGenEd");
        Panel panelOutcome = formview1.FindControl("panelOutcome");

    End If
End Sub

这也是说,checkGenEd和panelOutcome没有声明。

It's also saying that checkGenEd and panelOutcome are not declared.

编辑:我改变了我的code本,但它仍然无法正常工作:

I changed my code to this but it still doesn't work:

Protected Sub FormView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.DataBound
    If FormView1.CurrentMode = FormViewMode.Edit Then

        Dim checkGenEd As CheckBox = FormView1.FindControl("checkGenEd")
        Dim panelOutcome As Panel = FormView1.FindControl("panelOutcome")

        If checkGenEd.Checked = True Then
            panelOutcome.Visible = True
        Else
            panelOutcome.Visible = False
        End If

    End If
End Sub

有没有任何错误了,但是当我点击复选框没有任何反应。我认为需要有某种事件触发,但我不知道如何可以把一个事件处理程序的事件处理程序内。

There aren't any errors anymore, but nothing happens when I click the checkbox. I think there needs to be some kind of event to trigger it but I don't know how you can put an event handler inside of an event handler.

推荐答案

通过FormView控件,您必须使用找到的控制,如:

With FormView, you have to use find control, as in:

CheckBox checkGenEd = (CheckBox)formview1.FindControl("checkGenEd");
Panel panelOutcome = (Panel)formview1.FindControl("panelOutcome");

您不能直接ID参一控

心连心。

这篇关于ASP.NET,VB:如何访问从后面code一个FormView控件里面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆