Dynamic DataList from a Dataset

Posted on 2004-08-26
Last Modified: 2012-06-21
 I am new to the ASP.NET, C#.
My problem description is that I have to create a Glossary web page. The Glossary will have some major categories. Each major category will have different levels of sub-categoires.
Finally, the lowest level sub-categories will be linked to a Term table where the users will be provided with the term, definition. example use etc.

I would like to create a main datalist for the major categories. I would like LinkButton the categories. Depending on what the user clicks, it will bring the subcategories........finally once there is no more subcategories, it will bring the Term related data sources.

Can somebody please provide me with some insight as to how I should proceed with the problem from an abstract level. I will then collaborate/continue to explore the solution.


Question by:_Esam
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
LVL 17

Expert Comment

ID: 11903281
You will need to catch the selected index change of each dropdownlist.  Store the selected value, and the postback.  This will continue to drill down after the link, etc until you get to the bottom level.  Are you planning on doing this in a datagrid, datalist, etc or are you creating individual controls?



Accepted Solution

shovavnik earned 500 total points
ID: 11907043
By abstract, conceptually, do you refer only to the presentation layer, or to the whole process, including data retrieval?

Just for illustration, I'll assume a table with three columns, where the first column has the categories, the second has the subcategories, and the third has the terms.

One way to go about it is to use three data repeaters in a table.  The table is only for positioning in this case, and not for the data itself.

      <asp:DataRepeater id="CatRepeater" runat="server">
            <asp:LinkButton id="CatLink" runat="server"></asp:LinkButton>
      <asp:DataRepeater id="SubRepeater" runat="server">
            <asp:LinkButton id="SubLink" runat="server"></asp:LinkButton>
      <asp:DataRepeater id="TermRepeater" runat="server">
            <asp:LinkButton id="TermLink" runat="server"></asp:LinkButton>

And provide a label for the definition.

<asp:Label id="Definition" runat="server"></asp:Label>

Because you may not want to limit the user to haveing to go through all the different levels, it may make sense to work a querystring system, instead of a post back system.  This way, a user can link to a definition or a subcategory directly.

So you check the querystring in your Page_Load method, and based on that info choose which DataRepeaters to bind to data, and also which data to access.  For example, say you decide on a querystring format like this:
MyPage.aspx?cat={category id}&sub={sub-category id}&term={term id}
In Page_Load you can do something like this:

... Page_Load(...)
' always bind the categories, because the user sees them no matter what
CatRepeater.DataSource = GetCategoryDataSource()

' then get the category querystring
Dim qsCat = Request.QueryString("cat")
if not qsCat is nothing and not qsCat = String.Empty then
  SubRepeater.DataSource = GetSubCategoryDataSource( Convert.ToInt32( qsCat ))

  ' only if there's a subcategory can there be a terms list
  Dim qsSub = Request.QueryString("sub")
  ' same logic for the subcategory
  if not qsSub is nothing and not qsSub = String.Empty then
    TermRepeater.DataSource = GetTermDataSource( Convert.ToInt32( qsSub ))

    ' only if there's a term can there be a definition
    Dim qsTerm = Request.QueryString("term")
    ' same logic for the term
    if not qsTerm is nothing and not qsTerm = String.Empty then
      Definition.Text = GetDefinition( Convert.ToInt32( qsTerm ))
    end if
  end if
end if
end sub

Because lots of this data seems to be relatively constant, you cache the inital category list, or use page caching (I won't go into that here right now).
Getting the various data sources is a matter of retrieving lists from the database based on a "parent".  Essentially, this seems like a very simple data structure:

NodeID int
ParentID int (root categories have a null parentid)
Text string (nvarchar?)
optionally also a Type int field which designates "category", "subcategory", "term" or "definition".
You may want to put definitions in a separate table.

In any case, accessing any list can be done with a single query (stored procedure, preferably) - assuming SQL Server:
create procedure GetChildren
@ParentID int = null
select NodeID, Text
from TreeTable
where ParentID = @ParentID

Then your Get...DataSource() functions all call the same procedure to retrieve the data and bind it to the correct level of DataRepeater.

Let me know if this is clear.  It should give you a direction, even you don't go for this exactly.

Author Comment

ID: 11911057
Hi shovavnik,
Your explanation was very clear to me pertaining to the fact of assuming that I used VB and SQL server along with ASP.NET provided with the table structure as you described.
But I am constraint to using the ASP.NET with C# and OleDb (MS Access).
Please find below a detailed explanation of what I have at this moment for the problem and what I need to do.
For the moment, my class project member created three tables for the Glossary database.
They are: Category, Term, Category_Term (the link table for Category and Term)
Below is the structure of the

Category table:

Category_ID            Category                  Parent_ID
100                  Applications            0
101                  Usability                  0
102                  Algorithms                  0
103                  Guideline of usability            101
104                  Bloopers                  101
105                  User analysis            103
106                  Task analysis            103
107                  User characteristics            105
108                  User Demographics            105

Term table:


Category_Term table:

Category_ID (references Category_ID in Category table)
Term_ID (references Term_ID in Term table)      

As you can see from the Category table, a subcategory was defined in terms of parent ids.
Major categories can have different levels of subcategories. Also it is possible that term(s) can be at any sublevels (in multiple sublevels of a category….I can defer this part for future extension of the project). A term is related via the category ids.

I am totally open to restructure the table if it can fulfill the following criteria.

I should be able to list all the major categories at the start of the page like the following:



Once the user clicks the Usability, the user will see the following list.


Guidelines of usability

Once the user clicks the Guidelines of usability, the user will see the following:


Guidelines of usability


User analysis
Task analysis

And so on…. A maximum of 7 levels (as requested)

Once the user reaches the lowest level of a category/subcategory, the user will find the term and their associated information relating the Term table.

It might be desirable from a professional point of view to show a navigational link like….



Guidelines of usability>User analysis>User demographics



Instead of the format described earlier.

I am totally open to any suggestion that might direct the project to a successful completion.

I personally would like to use DataList or Repeaters for displaying the information with
C#.NET and OleDb (MS Access).

I need definite help on figuring out how I can capture the event from the user from the datalist/repeater and redirect the user to proper information display at proper stages. I lack proficiency in this area.

Any advice of the query would also be appreciated.
I have a tentative query that needs to identify the category id. How I do that?

Please advise me with your expertise.


Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 11925253
Note to participant experts.

Please note my intention of a request to the community support to delete this message.
I intend to provide a concrete example that will lead to a proper solution. Please note that there is no need to collaborate on this question anymore.


Author Comment

ID: 11938910
Although I requested to close this question,
I am making a request to reward "shovavnik" some points for solid efforts.


Author Comment

ID: 11959793
My sincere apology for not describing the problem statement of this question concisely.
I am brand new to the ASP.NET development.
I was expecting the answer to be in C#.
But the answer from "shovavnik" finally shed some light on my problem question.
I finally understood the problem in C# contex.
But I had to do some extensive research on this topic.
I believe it is best in my interest to reward "shovavnik" the full points.
I am making a request to do that.
But I still need to have this question closed.
Sorry for any inconveniences on this regard.

Thanks to shovavnik.


Expert Comment

ID: 11961705

Thanks for the points.

I used to give example in c#, but found that most people who don't state the language they're using generally use vb.  I missed the part in your question where you stated c#.  So I apologize.

I'm glad my advice helped you anyway.


Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question