Problem when adding a new repeater item for repeater that has a nested gridview RRS feed

  • Question

  • User646364117 posted

    I am adding an item to a repeater. I checked in the db and the item actually got added. At the end of my insert function I call a function that rebinds the repeater.

    In the repeater ItemDataBoundEvent the nested gridview is data binded.  I am getting a failure because btn_Insert could not be found. See code below. When I used the debugger, I saw that the failure occurred only  for the newly added repeater item.

    There is no error for previously existing repeater items. Why the error?

     Protected Sub rptBlock_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptBlock.ItemDataBound
            If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
                Dim hf As HiddenField = CType(e.Item.FindControl("hfBlockID"), HiddenField)
                Dim blockId As Integer
                blockId = Convert.ToInt16(hf.Value)
                'Dim lbl1 As Label = CType(e.Item.FindControl("lblBlockType"), Label)
                Dim hf1 As HiddenField = CType(e.Item.FindControl("hfBlockType"), HiddenField)
                Dim blocktype As String
                blocktype = hf1.Value.ToString
                Dim gv As GridView = CType(e.Item.FindControl("gvContent"), GridView)
                gv.DataSource = EMailGen3.GridviewContent.GetAllGridViewContents(blockId)
                If blocktype <> "Long Text" Then
                    gv.Columns(2).Visible = False
                End If
                Dim btn As ImageButton = CType(gv.FooterRow.FindControl("btn_Insert"), ImageButton)
                btn.CommandArgument = blockId.ToString()
                Dim pnl As Panel = CType(e.Item.FindControl("Panel1"), Panel)
                pnl.Visible = False
            End If
        End Sub

    Thursday, February 13, 2020 4:08 PM

All replies

  • User646364117 posted

    The problem was that I had not added any content data rows to the gridview so apparently the footer could not be found.

    When I added a dummy data row, the problem went away

    Thursday, February 13, 2020 6:26 PM