隐藏现有的Panel服务器端

时间:2015-08-19 18:00:25

标签: asp.net

我正在尝试使用服务器端代码隐藏基于值的面板。

  • 表单从对象数据源
  • 提供
  • 面板位于表单
  • 对象数据源触发CustomerDataSource_Selected子

Web form Code

服务器端代码执行

Public Sub CustomerDataSource_Selected(ByVal source As Object, ByVal e As ObjectDataSourceStatusEventArgs)
    Dim DisplayPanel As Boolean
    DisplayPanel = False
    If e.ReturnValue IsNot Nothing Then
        If e.ReturnValue(0).x1 < e.ReturnValue(0).x2 Then
            DisplayPanel = True
        End If
    End If

    Dim FPanel As Panel = CType(FormView.FindControl("FuturePanel"), Panel)
    FPanel.Visible = DisplayPanel 'here is the problem...
End Sub

我在下面得到了例外,因为sub&#34; CustomerDataSource_Selected&#34;由ObjectDataSource调用,它无法访问上述代码中表单的控件集合:

对象引用未设置为对象的实例。

如何使用当前sub隐藏面板,需要访问控件集合?

还记得从ObjectDataSource调用sub吗?

这可能吗?

1 个答案:

答案 0 :(得分:1)

看起来像

Dim FPanel As Panel = CType(FormView1.Row.Cells[0].FindControl("FuturePanel"), Panel)

没有获得控制权。 (FPanel == Null)

试试这个......

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
    if (segue.identifier == "helpUpdateProfile" ){
        var detailVC = segue.destinationViewController as DetailVC;
        detailVC.toPass = "help"

    }
}