DeveloperBarn Forums

DeveloperBarn

Programming & IT forum

reference control from nested repeater

This is a discussion on reference control from nested repeater within the .Net Development forums, part of the Programming & Scripting category; Hi guys I have 3 repeater controls: Code: rpActiveCategory rpActiveSubCategory rpActiveSpecs rpActiveSubCategory is populated inside of rpActiveCategory's OnItemDataBound rpActiveSpecs populating ...

Go Back   DeveloperBarn Forums > Programming & Scripting > .Net Development

  #1  
Old September 15th, 2008, 04:30 AM
Shem's Avatar
Barn Enthusiast
 
Join Date: Mar 2008
Posts: 292
Rep Power: 2
Shem is on a distinguished road
Default 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
Reply With Quote
  #2  
Old September 15th, 2008, 06:12 AM
richyrich's Avatar
Administrator
 
Join Date: Mar 2008
Real name: Rich
Location: Somewhere only we know...
Posts: 1,347
Blog Entries: 6
Rep Power: 8
richyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to all
Default

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.
Reply With Quote
  #3  
Old September 15th, 2008, 06:24 AM
Shem's Avatar
Barn Enthusiast
 
Join Date: Mar 2008
Posts: 292
Rep Power: 2
Shem is on a distinguished road
Default

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.
Reply With Quote
  #4  
Old September 15th, 2008, 07:10 AM
richyrich's Avatar
Administrator
 
Join Date: Mar 2008
Real name: Rich
Location: Somewhere only we know...
Posts: 1,347
Blog Entries: 6
Rep Power: 8
richyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to all
Default

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?
Reply With Quote
  #5  
Old September 15th, 2008, 07:21 AM
Shem's Avatar
Barn Enthusiast
 
Join Date: Mar 2008
Posts: 292
Rep Power: 2
Shem is on a distinguished road
Default

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?
Reply With Quote
  #6  
Old September 15th, 2008, 07:37 AM
richyrich's Avatar
Administrator
 
Join Date: Mar 2008
Real name: Rich
Location: Somewhere only we know...
Posts: 1,347
Blog Entries: 6
Rep Power: 8
richyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to all
Default

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?
Reply With Quote
  #7  
Old September 15th, 2008, 07:42 AM
Shem's Avatar
Barn Enthusiast
 
Join Date: Mar 2008
Posts: 292
Rep Power: 2
Shem is on a distinguished road
Default

I think so...

what is, and how do i pass the item index for each repeater?
Reply With Quote
  #8  
Old September 15th, 2008, 08:01 AM
richyrich's Avatar
Administrator
 
Join Date: Mar 2008
Real name: Rich
Location: Somewhere only we know...
Posts: 1,347
Blog Entries: 6
Rep Power: 8
richyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to all
Default

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.
Reply With Quote
  #9  
Old September 15th, 2008, 08:50 AM
Shem's Avatar
Barn Enthusiast
 
Join Date: Mar 2008
Posts: 292
Rep Power: 2
Shem is on a distinguished road
Default

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:
Reply With Quote
  #10  
Old September 15th, 2008, 09:08 AM
richyrich's Avatar
Administrator
 
Join Date: Mar 2008
Real name: Rich
Location: Somewhere only we know...
Posts: 1,347
Blog Entries: 6
Rep Power: 8
richyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to all
Default

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 With Quote
Reply

  DeveloperBarn Forums > Programming & Scripting > .Net Development

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads

Thread Thread Starter Forum Replies Last Post
VBScript Functions Reference jmurrayhead ASP Development 25 October 21st, 2008 08:31 AM
Access parent repeater item from child repeater Shem .Net Development 10 September 9th, 2008 05:03 AM
paging enabled in a repeater control peebman2000 .Net Development 6 September 4th, 2008 11:15 AM
convert repeater to pdf peebman2000 .Net Development 4 August 18th, 2008 09:39 AM
Dynamically Reference Worksheet Cell/Range BLaaaaaaaaaarche Microsoft Office 2 June 18th, 2008 03:59 PM


All times are GMT -4. The time now is 04:16 PM.


Copyright ©2008-2010, DeveloperBarn

Content Relevant URLs by vBSEO 3.3.2