Solved

Dynamic DataList from a Dataset

Posted on 2004-08-26
9
595 Views
Last Modified: 2012-06-21
Hi,
 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.

Thanks.

_Esam
0
Comment
Question by:_Esam
  • 4
  • 2
9 Comments
 
LVL 17

Expert Comment

by:AerosSaga
Comment Utility
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?

Regards,

Aeros
0
 
LVL 8

Accepted Solution

by:
shovavnik earned 500 total points
Comment Utility
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.

<table>
  <tr>
    <th>Categories</th>
    <th>Subcategories</th>
    <th>Terms</th>
  </tr>
  <tr>
    <td>
      <asp:DataRepeater id="CatRepeater" runat="server">
        <ItemTemplate>
          <div>
            <asp:LinkButton id="CatLink" runat="server"></asp:LinkButton>
          </div>
        </ItemTemplate>
      </asp:DataRepeater>
    </td>
  </tr>
  <tr>
    <td>
      <asp:DataRepeater id="SubRepeater" runat="server">
        <ItemTemplate>
          <div>
            <asp:LinkButton id="SubLink" runat="server"></asp:LinkButton>
          </div>
        </ItemTemplate>
      </asp:DataRepeater>
    </td>
  </tr>
  <tr>
    <td>
      <asp:DataRepeater id="TermRepeater" runat="server">
        <ItemTemplate>
          <div>
            <asp:LinkButton id="TermLink" runat="server"></asp:LinkButton>
          </div>
        </ItemTemplate>
      </asp:DataRepeater>
    </td>
  </tr>
</table>

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()
CatRepeater.DatBind()

' 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 ))
  SubRepeater.DataBind()

  ' 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 ))
    TermRepeater.DataBind()

    ' 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
as
select NodeID, Text
from TreeTable
where ParentID = @ParentID
go

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.
0
 

Author Comment

by:_Esam
Comment Utility
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:

Term_ID
Term_Definition
Term_Part0fSpeech
Term_Etc


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:


 
Categories:

Applications
Usability
Algorithms

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


Categories:
            
Usability

Subcategories:
            
Guidelines of usability
Bloopers

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

Categories:
            
Usability

Subcategories:
            
Guidelines of usability
Bloopers

Sub-subcategories:

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….


Category:
Usability

Subcategory:

Guidelines of usability>User analysis>User demographics

Terms:

TermA
TermB
TermC

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.

Sincerely,

_Esam
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:_Esam
Comment Utility
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.

Thanks.
_ESam
0
 

Author Comment

by:_Esam
Comment Utility
Although I requested to close this question,
I am making a request to reward "shovavnik" some points for solid efforts.

Thanks.
0
 

Author Comment

by:_Esam
Comment Utility
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.

_Esam.
0
 
LVL 8

Expert Comment

by:shovavnik
Comment Utility
_Esam,

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.

Regards.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now