如何在表对象中查找控件?

时间:2016-11-30 14:19:37

标签: vb.net

我试图在Table对象中找到文本框控件而不先将其写入页面。我需要一种有效的方法来查找这些控件,以免降低网站速度。

通过调用report_writer类型的新对象

创建表
Public ReportTable As Table
Public SectionID As Integer
Public ErrorList As List(Of String)
Public Sub New(ByVal SectionID As Integer, ByVal InitiativeID As Integer, ByVal AgencyID As Integer, ByVal ReportID As Integer, ByVal Printed As Boolean, ByVal Blank As Boolean)
    Me.SectionID = SectionID
    ErrorList = New List(Of String)
    ReportTable = WriteSection(SectionID, InitiativeID, AgencyID, Blank, Printed, ReportID, 1)
End Sub

显示在上面并将其存储在对象的ReportTable变量中。

在创建表之后,需要对表执行一些功能(例如自动完成和验证),以便在最终将表写入页面之前为用户编辑表的格式。

我遇到的问题是FindControl在自动完成和验证方法中不起作用,并且没有将Object引用设置为对象错误的实例。

'Finds the Table all of the controls are stored in
 Dim matrixTable As Table = ReportTable
 Dim TextBoxValues As New ArrayList
 Dim txt As TextBox
    'Loops through each item in the Array Lists of Heading and QuestionIDs to find a specific Textbox 
    For index As Integer = 0 To (HeadingCount - 1)
            txt = matrixTable.FindControl("txt_" & RightHeadingGroup(index) & "-" & RightQuestionGroup(index))
            If String.IsNullOrEmpty(txt.Text) Then
                 TextBoxValues.Add(0)
            Else
                TextBoxValues.Add(txt.Text)
            End If

    Next

以上是我尝试在页面中查找文本框的示例。

This is what the final table will resemeble

上面是完成后的表格会是什么样的。

0 个答案:

没有答案