+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 19

Thread: reference control from nested repeater

  1. #1
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    305
    Rep Power
    4

    reference control from nested repeater

    Hi guys

    I have 3 repeater controls:
    Code:
    rpActiveCategory
    rpActiveSubCategory
    rpActiveSpecs
    
    rpActiveSubCategory is populated inside of rpActiveCategory's OnItemDataBound

    rpActiveSpecs populating needs to be done from a sub that can be called where
    needed as this holds the records, so on updates i need to re-populate it.

    problem is i'm struggeling to reference controls inside of rpActiveSpecs in
    the sub, I can reference them from rpActiveSubCategory's OnItemDataBound but that doesn't help me

    here's my sub to populate rpActiveSpecs: (check bits in red)
    Code:
    Public Sub Populate_rpActiveSpecs(ByVal myParams As Params)
            ActiveSpecsPagedData.DataSource = SpecsManager.GetList(myParams)
            If myParams.ActivatedPage = 0 Then
                myParams.ActivatedPage = 0
                ActiveSpecsPagedData.CurrentPageIndex = 0
            Else
                ActiveSpecsPagedData.CurrentPageIndex = myParams.ActivatedPage
            End If
    
            'set datasource parameters
            ActiveSpecsPagedData.AllowPaging = True
            ActiveSpecsPagedData.PageSize = 25
    
            myParams.PageCount = ActiveSpecsPagedData.PageCount
            'btnPrev.Text = "<"
            'btnPrev.Visible = (Not ActiveSpecsPagedData.IsFirstPage)
    
            'btnNext.Text = ">"
            'btnNext.Visible = (Not ActiveSpecsPagedData.IsLastPage)
    
            'lblActivePagingPages.Text = "Page " & ActiveSpecsPagedData.CurrentPageIndex + 1 & " of " & ActiveSpecsPagedData.PageCount
            'lblActivePagingPages.CssClass = "PageNumbers"
    
            'for paging
            If ActiveSpecsPagedData.PageCount = 0 Then
                'lblActivePagingPages.Visible = False
                'btnNext.Visible = False
                'btnPrev.Visible = False
            Else
                'lblActivePagingPages.Visible = True
            End If
    
            'for sorting
            Dim lbtnActiveRoomNo As LinkButton = FindControl("lbtnActiveRoomNo")
            Dim lbtnActiveSpecNo As LinkButton = FindControl("lbtnActiveSpecNo")
            Dim lbtnActiveQty As LinkButton = FindControl("lbtnActiveQty")
            Dim lbtnActiveUnit As LinkButton = FindControl("lbtnActiveUnit")
            Dim lbtnActiveDescription As LinkButton = FindControl("lbtnActiveDescription")
            If ActiveSpecsPagedData.Count <= 1 Then
                lbtnActiveRoomNo.Enabled = False
                lbtnActiveSpecNo.Enabled = False
                lbtnActiveQty.Enabled = False
                lbtnActiveUnit.Enabled = False
                lbtnActiveDescription.Enabled = False
            Else
                lbtnActiveRoomNo.Enabled = True
                lbtnActiveSpecNo.Enabled = True
                lbtnActiveQty.Enabled = True
                lbtnActiveUnit.Enabled = True
                lbtnActiveDescription.Enabled = True
            End If
    
            'only bind data if there is data
            If ActiveSpecsPagedData.PageCount > 0 Then
                Dim rpActiveSpecs As Repeater = FindControl("rpActiveSpecs")
                rpActiveSpecs.DataSource = ActiveSpecsPagedData
                rpActiveSpecs.DataBind()
            End If
        End Sub
    
    any ideas or workarounds?
    Shem

  2. #2
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    On what action and in what repeater do you need to access rpActiveSpecs?

    I'm not quite getting what you're changing and where it is that then needs to update rpActiveSpecs.

  3. #3
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    305
    Rep Power
    4

    hi RR

    well i need to call on Populate_rpActiveSpecs whenever i need to re-populate
    that repeater it binds to.

    eg, after i update some data, i ned to call Populate_rpActiveSpecs.
    the prob is that rpActiveSpecs is a nested repeater, so I can't reference it's
    controls from code-behind.

    I need to be able to reference rpActiveSpecs contols.
    rpActive specs is the 2nd nested repeater ie.

    1. rpActiveCategory
    2. rpActiveSubCategory
    3. rpActiveSpecs

    Does it make sense now, basically i need to be able to reference controls
    fom rpActiveSpecs.

  4. #4
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    So, do you have an "Update" button in your rpActiveSpecs Item?

    And that fires a sub when it's clicked? You must then be referencing the RepeaterItem in this sub to know which item you're updating?

    From that RepeaterItem, you should be able to work back to create an instance of the Repeater using RepeaterItem.parent.

    Is that how your code is working? Does that make sense?

  5. #5
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    305
    Rep Power
    4

    I have an update button in my ModalPopup, that then fires a update sub,
    after the data has been updated i want to call Populate_rpActiveSpecs(),
    so that the repeater rpActiveSpecs will show the updated data.

    I also have another sub for 'sorting by field' which also needs to reference
    the controls inside of rpActiveSpecs, so there again i need to be able to
    reference them.

    so far the only way i've had any luck referencing controls in rpActiveSpecs is
    via rpActiveSubCategory's OnItemDataBound.

    There must be a way to reference them outside of rpActiveSubCategory's OnItemDataBound?

  6. #6
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    The only logic I can think of that should work is to pass the item index for each repeater into your Update sub.

    Then, starting from the top, you can create an instance of a RepeaterItem of the initial repeater, then find the next repeater control and create an instance of the RepeaterItem of this one, then find the repeater control of the one you want to update and fire a sub to update the data in it.

    So maybe have hiddenfields in your modalpopup with rpActiveCategory selected index and rpActiveSubCategory selected index. Then you can create an instance of each repeater item from the index.

    Does that make sense?

  7. #7
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    305
    Rep Power
    4

    I think so...

    what is, and how do i pass the item index for each repeater?

  8. #8
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Will need a bit of playing around with, but in your OnItemDataBound for rpActiveSpecs, use item.parent until you find the sub category repeateritem and get the index value of it and do the same for the category repeateritem.

    What I tend to do is write out the e.parent.parent (assuming e is the event variable in your OnItemDataBound rpActiveSpecs sub) into a label or something, until you find the item type you're looking for. I think .parent.parent should be the repeateritem of rpActiveSubCategory and .parent.parent.parent.parent should be the item of rpActiveCategory.

  9. #9
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    305
    Rep Power
    4

    Hey RR,

    can ya have a look at what i got here, it recognises my repeaters, but i still get a Null Reference when trying to reference one of my rpActiveSpecs controls...

    Code:
    Dim categoryCount As Integer = 0
            Dim subcategoryCount As Integer = 0
            Dim specsCount As Integer = 0
    
            Dim rpCategory As Repeater = rpActiveCategory
            For categoryCount = 0 To rpCategory.Items.Count - 1
    
                Dim rpSubCategory As Repeater = CType(rpCategory.Items(categoryCount).FindControl("rpActiveSubCategory"), Repeater)
                For subcategoryCount = 0 To rpSubCategory.Items.Count - 1
    
                    Dim rpSpecs As Repeater = CType(rpSubCategory.Items(subcategoryCount).FindControl("rpActiveSpecs"), Repeater)
                    For specsCount = 0 To rpSpecs.Items.Count - 1
    
                        Dim lbtnActiveRoomNo As LinkButton = CType(rpSpecs.Items(specsCount).FindControl("lbtnActiveRoomNo"), LinkButton)
                        Dim lbtnActiveSpecNo As LinkButton = CType(rpSpecs.Items(specsCount).FindControl("lbtnActiveSpecNo"), LinkButton)
    
                        lbtnActiveRoomNo.CommandArgument = "sh!t"
                    Next
                Next
            Next
    
    the bit in red gives the error:
    Code:
    System.NullReferenceException was unhandled by user code
      Message="Object reference not set to an instance of an object."
      Source="App_Web_6ilwnity"
      StackTrace:
           at CustomControls_specs_interior.ActiveSortbuttons_OnClick(Object s, EventArgs e) in C:\inetpub\wwwroot\keithdesign\CustomControls\specs_interior.ascx.vb:line 496
           at System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e)
           at System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument)
           at System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
           at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
           at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
           at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
      InnerException:
    

  10. #10
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Why not just use:-
    Code:
    For Each Item as RepeaterItem in spSpecs.Items
    
    instead of
    Code:
    For specsCount = 0 To rpSpecs.Items.Count - 1
    

+ Reply to Thread
Page 1 of 2 1 2 LastLast

Similar Threads

  1. VBScript Functions Reference
    By jmurrayhead in forum ASP Development
    Replies: 25
    Last Post: October 21st, 2008, 09:31 AM
  2. Access parent repeater item from child repeater
    By Shem in forum .NET Development
    Replies: 10
    Last Post: September 9th, 2008, 06:03 AM
  3. paging enabled in a repeater control
    By peebman2000 in forum .NET Development
    Replies: 6
    Last Post: September 4th, 2008, 12:15 PM
  4. convert repeater to pdf
    By peebman2000 in forum .NET Development
    Replies: 4
    Last Post: August 18th, 2008, 10:39 AM
  5. Dynamically Reference Worksheet Cell/Range
    By BLaaaaaaaaaarche in forum Microsoft Office
    Replies: 2
    Last Post: June 18th, 2008, 04:59 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO