Get Data from Repeater Control

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jcas1411
    New Member
    • Mar 2008
    • 4

    Get Data from Repeater Control

    Okay, I have found a suggested C# solution that syntatically ported to VB.NET seemed to look right however getting a Null pointer exception when i try to get data from the control..
    Code:
    Dim details As New objFilingDetails
    Dim item As RepeaterItem
            
    For Each item In Repeater1.Items
            'the repeater contains datarow views, each row 3 textboxes, 1 label
    
           Dim dtrow As Data.DataRowView = CType(item.DataItem, Data.DataRowView)
    
    'gets to here....mouse over in debug shows item.DataItem is Nothing
    'however does show two items in Repeater1.Items
    
                details.Description = (CType(dtrow.Item("txtbx_Documents"), TextBox)).Text
                details.FAA_Advance = Decimal.FromOACurrency((CType(dtrow.Item("txtbx_FAAFee"), TextBox)).Text)
                details.Aero_Fee = Decimal.FromOACurrency((CType(dtrow.Item("txtbx_AeroFee"), TextBox)).Text)
                details.FAA_Number = (CType(dtrow.Item("lbl_FAANo"), Label)).Text
    
                objFiling.Details.Add(details)
    
    Next
    Using a user control as basically 1 label 1 multiline textbox and 2 textboxes
    wrote a ItemBound function in the forms codebehind and a setData in the code behind for the control...
    Code:
     Private Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles Repeater1.ItemDataBound
            If (e.Item.ItemType = ListItemType.Item) Then
                CType(e.Item.FindControl("filing"), _
                   filingControl).SetData(CType(e.Item.DataItem, _
                   Data.DataRowView), False)
            End If
            If (e.Item.ItemType = ListItemType.AlternatingItem) Then
                CType(e.Item.FindControl("filing"), _
                   filingControl).SetData(CType(e.Item.DataItem, _
                   Data.DataRowView), True)
            End If
    
        End Sub
    
    
     Public Sub SetData(ByVal dr As Data.DataRowView, ByVal IsAlternating As Boolean)
    
            Me.lbl_FAANo.Text = dr("FAA_Number")
            Me.txtbx_Documents.Text = dr("Description")
            Me.txtbx_FAAFee.Text = FormatCurrency(dr("FAA_Advance"), 2)
            Me.txtbx_AeroFee.Text = FormatCurrency(dr("Aero_Fee"), 2)
    
            If IsAlternating Then
                Panel1.BackColor = Drawing.Color.LightGoldenrodYellow
            End If
    
    
        End Sub

    ............... ..sets great.......... ..just can't seem to figure out how to get the data back from the textboxes (user edits) or label without this Null Pointer Exception
  • jcas1411
    New Member
    • Mar 2008
    • 4

    #2
    Sweet, figured out my own problem after a little sleep. Basically my repeater didn't contain a datarowview object, it contained a UserControl that contained the datarowview object.... so my solution, add a getData() function in my user control and return the object it contains. In the codebehind for the form find user control and assign it to an object...workes and is clean.

    Code:
      Function GetData() As objFilingDetails
            Dim adetail As New objFilingDetails
            adetail.FAA_Number = Me.lbl_FAANo.Text
            adetail.Description = Me.txtbx_Documents.Text
            adetail.FAA_Advance = Convert.ToDecimal(Me.txtbx_FAAFee.Text.Trim("(", "$", ")"))
            adetail.Aero_Fee = Convert.ToDecimal(Me.txtbx_AeroFee.Text.Trim("(", "$", ")"))
    
            Return adetail
        End Function
    
    'and in the codebehind
         Dim details As New objFilingDetails
            Dim item As RepeaterItem
            For Each item In Repeater1.Items
    
                details = CType(item.FindControl("filing"), filingControl).GetData()
                objFiling.Details.Add(details)
    
            Next

    Comment

    Working...