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 ...
| |||||||
|
#1
| ||||
| ||||
| Hi guys I have 3 repeater controls: Code: rpActiveCategory rpActiveSubCategory rpActiveSpecs 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
Shem |
|
#2
| ||||
| ||||
| 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
| ||||
| ||||
| 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
| ||||
| ||||
| 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
| ||||
| ||||
| 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
| ||||
| ||||
| 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
| ||||
| ||||
| I think so... what is, and how do i pass the item index for each repeater? |
|
#8
| ||||
| ||||
| 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
| ||||
| ||||
| 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
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:
|
![]() |
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
| ||||
| 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 |