Categories and subcategories

Categories and subcategories

Old forum URL: forums.lhotka.net/forums/t/3511.aspx


ajj3085 posted on Tuesday, September 11, 2007

Hi,

I'm doing an asp.net application now, its been a while.  I have business objects, categories, which can contain subcategories as well.  I'm trying to display these in an a simple unordered list.

I'm stumbling on how to get the subcategories displayed.  I tried having a repeater contained in the ItemTemplate of the categories repeater, and setting its datasource, but nothing displayed.

Any ideas?  Any other better controls for this?

Thanks
Andy

JoeFallon1 replied on Tuesday, September 11, 2007

Andy,

I have used nested repeaters for a long time with CSLA and they work just fine.

Your idea is 100% correct - add the 2nd repeater in the Item Template of the first.

In rptr1_ItemDataBound you have to have code like this:

'call this after all the values in the main repeater are set.
'ItemDataBound will then run for all the values in the nested repeater.
mFilteredList = GetDataSource(mKey)

Dim rptr2 As Repeater = CType(e.Item.FindControl("rptr2"), Repeater)
rptr2.DataSource = mFilteredList
rptr2.DataBind()

Then you need a function like this:

Protected Function GetDataSource(ByVal key As Integer) As ObjectListView
 
Dim list As ObjectListView = Util.GetObjectListView(mColl, mSortExpression, mSortDirection)
  list.Filter =
"key=" & CStr(key)
 
Return list
End Function

Note:
The ObjectListView filtering is slower than Rocky's FilteredBindingList. It allows multi-property sorting and I want to use it for both sorting and filtering. But if you have large lists that get filtered often, you may want to use Rocky's instead.

I also handle rptr2_ItemDataBound and assign values to the controls. (I use a lot of hyperlinks and find it easier to handle in code.)

Something like this:

Protected Sub rptrData_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs)

If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
 
Dim mIndex As Integer = e.Item.ItemIndex
 
Dim mObjInColl As SomeType = CType(mFilteredList.Item(mIndex).Object, SomeType)

 
Dim oHylNumber As HyperLink = CType(e.Item.FindControl("hylNumber"), HyperLink)

 oHylNumber.NavigateUrl =
"Win('SomePage.aspx?keyvalue=" & mObjInColl.key & "&viewtype=1','MyScreen',600,500);"

 
oHylNumber.Text = mObjInColl.Number

etc.

Joe

 

ajj3085 replied on Tuesday, September 11, 2007

Ahh, that's it.  I forgot the call to .DataBind.  Opps...

I don't think I'll need the OLV though, everything is sorted by the business layer (no user sortable items here).

Thanks
Andy

NightOwl888 replied on Thursday, November 08, 2007

Hi,

I am working with an older version of CSLA - version 1.51 (upgraded for .NET 2.0 to be exact).  I haven't purchased the books on 2.0 or 3.0 yet. Unfortunately, I don't have the luxury of time right now to learn and upgrade.

I am trying to accomplish nested repeaters similar to this example. Actually, what I would like to do is have something that looks like this blog: http://chrisdodd.com/blog. Specifically, I would like to have a repeated list (with paging) on the outside and on the bottom of each post display a list of categories it belongs to. The category list should be horizontal but wrap when it gets to the end of the available space. Given the fact that there are no ObjectListView or FilteredBindingList objects in my version of the framework, is something like this still possible with CSLA and ASP.NET?

I have been playing with this trying to get it working, but can't seem to find a solution.

By the way, the post - category relationship is many to many with a database table to resolve the relationship.

NightOwl888

Copyright (c) Marimer LLC