bulletted lists

M

Martin

Hi,

I am new to ASP.NET and am having problems trying to develop a fairly simple
user control.

I have a DB table similar to the following -

Category,Item
cat1,item1
cat1,item2
cat1,item3
cat2,item1
cat2,item2

and I want to use it to generate simple bulletted lists, such as -

cat1
-item1
-item2
-item3

cat2
-item1
-item2

The following is a sample of my code -

01: <%@ Import Namespace="System.Data" %>
02: <%@ Import Namespace="System.Data.OleDb" %>
03:
04: <script language="VB" runat="server">
05: dim conn as new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Martin\list.mdb")
06: dim ds as DataSet = new DataSet()
07:
08: sub Page_Load(Sender as Object, e as EventArgs)
09: 'open connection
10: dim cmdGetCat as new OleDbDataAdapter("SELECT DISTINCT category FROM
list",conn)
11: dim cmdGetItems as new OleDbDataAdapter("SELECT * FROM list", conn)
12:
13: 'fill dataset
14: cmdGetCat.Fill(ds, "Categories")
15: cmdGetItems.Fill(ds, "Items")
16:
17: 'bind to server control
18: rptrCategories.DataSource = ds.Tables("Categories").DefaultView
19: DataBind()
20: end sub
21:
22: sub rptrCategories_ItemCreated(Sender As Object, e As
RepeaterItemEventArgs)
23: rptrItems.DataSource = ds.Tables("Items").Select("category = '" &
e.Item.Container.DataItem("category") & "'")
24: DataBind()
25: end sub
26:
27: </script>
28:
29: <ASP:Repeater id="rptrCategories"
OnItemCreated="rptrCategories_ItemCreated" runat="server" >
30: <ItemTemplate>
31:
32: <font size="3" face="Arial, Helvetica, sans-serif"><%#
Container.DataItem("category") %></font><br>
33:
34: <ASP:Repeater id="rptrItems" runat="server" >
35: <HeaderTemplate>
36: <ul>
37: </HeaderTemplate>
38:
39: <ItemTemplate>
40: <li><font size="2" face="Arial, Helvetica, sans-serif"><%#
Container.DataItem("item") %></font></li>
41: </ItemTemplate>
42:
43: <FooterTemplate>
44: </ul>
45: </FooterTemplate>
46: </ASP:Repeater>
47: </ItemTemplate>
48: </ASP:Repeater>

I have a few problems with this -

1/ When I try to use it I get "Compiler Error Message: BC30451: Name
'rptrItems' is not declared." for line 23. It is declared on line 34. Is it
something to do with the fact that the sub is related to the parent repeater
and not the page object?

2/ Once I get problem 1 solved I am actually still expecting a problem with
line 23. Specifically, I made a wild guess at how to access the current
value of the parent repeater and used
"e.Item.Container.DataItem("category")", will this work and, if not, what
would?

3/ What will be the effect of the multiple databinds?

4/ I would prefer to only connect to the DB once, get the contents of the
table and manipulate the dataset to get my values. But, there doesn't seem
to be a way of filtering a datatable to obtain distinct values.

Sorry about all the questions.

Thanks
Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Retrieving and copying element from array 10
No data showing in Repeater / DataList ect 0
repeater 0
Nested Repeater 0
Repeater Question 2
Delete rows in Gridview 0
DataBind 1
Help with my responsive home page 2

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top