473,382 Members | 1,658 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How do I bind an array to a repeater?

Hello folks,

How do I bind an array to a repeater?

or bind an array to a hyperlink (which is repeated inside a
repeater) ?

I get this message:

Compiler Error Message: BC30456: 'DataItem' is
not a member of 'System.Web.UI.Control'.

for line below that begins with <li>

This is my simplified example code. I have included 2 examples
both of which fail.

+++ +++ +++ +++
<Script Runat="Server">

Sub Page_Load()
Dim aryDates() As String = {"2004-07-04", "2004-07-05",
"2004-07-06"}

rptRHS_Menu.DataSource = aryDates
rptRHS_Menu.DataBind()

End Sub

</Script>

<html>
<body>
<asp:Repeater
ID="rptRHS_Menu"
Runat="Server" />
<ItemTemplate>
<li><a href="<%# String.Concat( Container.DataItem,
".html") %>"><%# Container.DataItem %></a></li>
</ItemTemplate>
</asp:Repeater>
</body>
</html>
+++ +++ +++ +++

<Script Runat="Server">
Sub Page_Load()
Dim aryDates As ArrayList
aryDates = New ArrayList

aryDates.Add ("2004-07-04")
aryDates.Add ("2004-07-05")
aryDates.Add ("2004-07-06")

aryDates.Reverse

rptRHS_Menu2.DataSource = aryDates
rptRHS_Menu2.DataBind()
End Sub
</Script>
<html>
<body>
<form Runat="Server">
<asp:Repeater
ID="rptRHS_Menu2"
Runat="Server" />
<ItemTemplate>
<li>
<a href='<%# String.Format( "{0}.html",
Container.DataItem ) %>'><%# String.Format( "{0}",
Container.DataItem) %></a>
</ItemTemplate>
</asp:Repeater>
</form>
</body>
</html>

Nov 18 '05 #1
6 6624
Oh my God. I've been told I can't do it. I have to put the data
into a hash table and add that to the array. Like this:

Surely there is a simpler way. Why can't I just refer to the
bound array as Container.DataItem(0) ?

I'm sure I've seen examples like that.

Here is the solution that's been indicated to me. There must be
a simpler way than this:

++ ++ ++ ++
<%@ Page Language="VB" %>
<script runat="server">

Function Add2Hash(dtd As String) As HashTable
Dim hshDates As HashTable
hshDates = New HashTable()
hshDates.Add("Date", dtd)
Return hshDates
End Function

Sub Page_Load(sender as Object, e as EventArgs)

Dim aryDates As ArrayList
aryDates = New ArrayList

aryDates.Add(Add2Hash("2004-07-04"))
aryDates.Add(Add2Hash("2004-07-05"))
aryDates.Add(Add2Hash("2004-07-06"))

aryDates.Reverse

rptRHS_Menu3.DataSource = aryDates
rptRHS_Menu3.DataBind()

End Sub

</script>

<html>
<head>
</head>
<body>
<form Runat="Server">
<ul>
<asp:Repeater id="rptRHS_Menu3" Runat="Server">
<ItemTemplate>
<li><a href='<%# String.Format("{0}.html",
Container.DataItem.Item("Date")) %>'><%#
Container.DataItem.Item("Date") %></a></li>
</ItemTemplate>
</asp:Repeater>
</ul>
</form>
</body>
</html>

Nov 18 '05 #2
Oh my God. I've been told I can't do it. I have to put the data
into a hash table and add that to the array. Like this:

Surely there is a simpler way. Why can't I just refer to the
bound array as Container.DataItem(0) ?

I'm sure I've seen examples like that.

Here is the solution that's been indicated to me. There must be
a simpler way than this:

++ ++ ++ ++
<%@ Page Language="VB" %>
<script runat="server">

Function Add2Hash(dtd As String) As HashTable
Dim hshDates As HashTable
hshDates = New HashTable()
hshDates.Add("Date", dtd)
Return hshDates
End Function

Sub Page_Load(sender as Object, e as EventArgs)

Dim aryDates As ArrayList
aryDates = New ArrayList

aryDates.Add(Add2Hash("2004-07-04"))
aryDates.Add(Add2Hash("2004-07-05"))
aryDates.Add(Add2Hash("2004-07-06"))

aryDates.Reverse

rptRHS_Menu3.DataSource = aryDates
rptRHS_Menu3.DataBind()

End Sub

</script>

<html>
<head>
</head>
<body>
<form Runat="Server">
<ul>
<asp:Repeater id="rptRHS_Menu3" Runat="Server">
<ItemTemplate>
<li><a href='<%# String.Format("{0}.html",
Container.DataItem.Item("Date")) %>'><%#
Container.DataItem.Item("Date") %></a></li>
</ItemTemplate>
</asp:Repeater>
</ul>
</form>
</body>
</html>

Nov 18 '05 #3
Zenobia:

The code you posted in your original example works fine for me.
Perhaps you could post the complete code as the error must be
somewhere else.

I assure you it is quite possible to bind to an array or an ArrayList.

--
Scott
http://www.OdeToCode.com

On Tue, 06 Jul 2004 14:29:33 +0100, Zenobia
<6.**********@spamgourmet.com> wrote:
Oh my God. I've been told I can't do it. I have to put the data
into a hash table and add that to the array. Like this:

Surely there is a simpler way. Why can't I just refer to the
bound array as Container.DataItem(0) ?

I'm sure I've seen examples like that.

Here is the solution that's been indicated to me. There must be
a simpler way than this:

++ ++ ++ ++
<%@ Page Language="VB" %>
<script runat="server">

Function Add2Hash(dtd As String) As HashTable
Dim hshDates As HashTable
hshDates = New HashTable()
hshDates.Add("Date", dtd)
Return hshDates
End Function

Sub Page_Load(sender as Object, e as EventArgs)

Dim aryDates As ArrayList
aryDates = New ArrayList

aryDates.Add(Add2Hash("2004-07-04"))
aryDates.Add(Add2Hash("2004-07-05"))
aryDates.Add(Add2Hash("2004-07-06"))

aryDates.Reverse

rptRHS_Menu3.DataSource = aryDates
rptRHS_Menu3.DataBind()

End Sub

</script>

<html>
<head>
</head>
<body>
<form Runat="Server">
<ul>
<asp:Repeater id="rptRHS_Menu3" Runat="Server">
<ItemTemplate>
<li><a href='<%# String.Format("{0}.html",
Container.DataItem.Item("Date")) %>'><%#
Container.DataItem.Item("Date") %></a></li>
</ItemTemplate>
</asp:Repeater>
</ul>
</form>
</body>
</html>


Nov 18 '05 #4
Zenobia:

The code you posted in your original example works fine for me.
Perhaps you could post the complete code as the error must be
somewhere else.

I assure you it is quite possible to bind to an array or an ArrayList.

--
Scott
http://www.OdeToCode.com

On Tue, 06 Jul 2004 14:29:33 +0100, Zenobia
<6.**********@spamgourmet.com> wrote:
Oh my God. I've been told I can't do it. I have to put the data
into a hash table and add that to the array. Like this:

Surely there is a simpler way. Why can't I just refer to the
bound array as Container.DataItem(0) ?

I'm sure I've seen examples like that.

Here is the solution that's been indicated to me. There must be
a simpler way than this:

++ ++ ++ ++
<%@ Page Language="VB" %>
<script runat="server">

Function Add2Hash(dtd As String) As HashTable
Dim hshDates As HashTable
hshDates = New HashTable()
hshDates.Add("Date", dtd)
Return hshDates
End Function

Sub Page_Load(sender as Object, e as EventArgs)

Dim aryDates As ArrayList
aryDates = New ArrayList

aryDates.Add(Add2Hash("2004-07-04"))
aryDates.Add(Add2Hash("2004-07-05"))
aryDates.Add(Add2Hash("2004-07-06"))

aryDates.Reverse

rptRHS_Menu3.DataSource = aryDates
rptRHS_Menu3.DataBind()

End Sub

</script>

<html>
<head>
</head>
<body>
<form Runat="Server">
<ul>
<asp:Repeater id="rptRHS_Menu3" Runat="Server">
<ItemTemplate>
<li><a href='<%# String.Format("{0}.html",
Container.DataItem.Item("Date")) %>'><%#
Container.DataItem.Item("Date") %></a></li>
</ItemTemplate>
</asp:Repeater>
</ul>
</form>
</body>
</html>


Nov 18 '05 #5
On Tue, 06 Jul 2004 11:02:07 -0400, Scott Allen
<bitmask@[nospam].fred.net> wrote:
Zenobia:

The code you posted in your original example works fine for me.
Perhaps you could post the complete code as the error must be
somewhere else.

I assure you it is quite possible to bind to an array or an ArrayList.


Thanks, but I think you must've fixed my code error when you got
it to work.

The error was due to an improperly closed <asp:repeater> tag.

I'm closing it here:

<asp:Repeater
ID="rptRHS_Menu"
Runat="Server" />

and including a </asp:Repeater> below that! The example should
be changed to

<asp:Repeater
ID="rptRHS_Menu"
Runat="Server">

for it to work.

The other 'solution' I posted in reply to this post was over
complex. I don't need the hash table.

Nov 18 '05 #6
Ah, yes. I had copied out just the text inside of <ItemTemplate>.

On Tue, 06 Jul 2004 18:41:25 +0100, Zenobia
<6.**********@spamgourmet.com> wrote:
On Tue, 06 Jul 2004 11:02:07 -0400, Scott Allen
<bitmask@[nospam].fred.net> wrote:
Zenobia:

The code you posted in your original example works fine for me.
Perhaps you could post the complete code as the error must be
somewhere else.

I assure you it is quite possible to bind to an array or an ArrayList.


Thanks, but I think you must've fixed my code error when you got
it to work.

The error was due to an improperly closed <asp:repeater> tag.


--
Scott
http://www.OdeToCode.com
Nov 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Frank | last post by:
Hi alll, How can I bind a dynamically created dataTable to a repeater? I do not know the number of columns and the column names at design time. I try to do the same thing as for datagrid:...
2
by: timmso | last post by:
I got this sample of code from Mike Moore in response to my question of how I create clickable links from a data source. <asp:Repeater id="Repeater1" runat="server"> <ItemTemplate>...
3
by: AFN | last post by:
I need to manually create the data to be shown in a datagrid (or some data table object). Should I create an array and bind the array to the datagrid OR should I create a temporary dataset and...
2
by: A Traveler | last post by:
Hi, I have a custom collection class i wrote, LineItemsCollection, which is a strongly typed collection of objects of my LineItem class. The LineItem class is a simple class with just a couple...
5
by: Jaybuffet | last post by:
a custom object. Similar to how I bind a collection of objects to a repeater. Is there a way to bind a single object to a Table? I could use a repeater, but seems over kill for a single object....
0
by: JP2006 | last post by:
I'm having an issue with a control I'm writing to consume RSS feeds. It gets a feed via a querystring parameter and sticks it in a dataset. I then use the dataset to write out the feed title and...
3
by: =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?= | last post by:
Hi; I have a Repeater control where in my code-behind I call: rptrProducts.DataSource = cart.CartItems; rptrProducts.DataBind(); And then in the aspx file I have: <asp:TextBox...
4
by: Pieter | last post by:
Hi, I want to bind a proeprty of a child object to a DataGridView, but it doesn't work. For instance: Imagen that I have an object Company, and this object company has a child object...
2
by: akshalika | last post by:
Hi, I have a repeater control. it dynamically bind textbox or dropdown base on some condition. i want to bind required field validator dynamically for validate textbox or dropdown. here is my...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.