Solved

Dynamic DataList from a Dataset

Posted on 2004-08-26
9
600 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
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?

Regards,

Aeros
0
 
LVL 8

Accepted Solution

by:
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.

<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
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:

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

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

Thanks.
_ESam
0
 

Author Comment

by:_Esam
ID: 11938910
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
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.

_Esam.
0
 
LVL 8

Expert Comment

by:shovavnik
ID: 11961705
_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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 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

16 Experts available now in Live!

Get 1:1 Help Now