I have 3 levels deep repeters which bind to the following:
MainCategories – bind to top repeater
SubCategories – bind to repeater in the 2nd level
SubSubCategories – bind to repeater in the 3rd level
Up to now, I acheived the databinding by using the itemdatabound event of the repeaters and passing the category id in order to filter the level beneath (e.g.: get all SubCategories for MainCategory 1, get all Subcategoris for MainCategory2).
This of course results in many trips to the database, and is inefficient.
Is there a way to make only 3 queries:
1. get all Main Categories and bind to top rpeater,
2. get all sub categories and bind somehow to 2nd level repeaters
3. get all subsub categories and bind to 3rd level repeaters.
How can this be acheived in asp.net c#?
To do so, please follow below steps:
First of all data into a DataTable say
dataTableMainCategoriesand then filterSubCategoriesandSubSubCategoriesfromdataTableMainCategoriesdata table. Finally, atItemDataBoundwrite below code block and forSubCategoriesandSubSubCategoriesDataTable add desired column before importing filtered rows.Populate all main categories into a table and Bind to MainCategory repeater (
rptrMainCategories) and the populate all sub and sub sub categories intodataTableCategoriesdata table.Update
If you use typed(custom typed) data then you can choose data in below ways:
At the event
rptrMainCategories_ItemDataBoundwrite below code and bind to repeater:At the event
rptrSubCategories_ItemDataBoundwrite below code and bind to repeater: