473,405 Members | 2,261 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,405 software developers and data experts.

Accessing array data with Repeater

Hi,

I have a Repeater control that is databound to an array. This array
contains data regarding products (ie. Name, Price, Manufacturer, etc.).

I am wondering how do I display data in a control that is contained in the
Repeater's ItemTemplate?
Here's my example code:

Sub BindToArray()
'code for the array omitted here
Me.Repeater1.DataSource = products
Me.Repeater1.DataBind()
End Sub

<asp:Repeater>
<ItemTemplate>
<!-- say that I wanted to bind to the Name field of the array
<asp:Label id=Label1 Text=<%#
Container.DataItem("Name")%>></asp:Label>
</ItemTemplate>
</asp:Repeater>

Would this code work?

Roshawn
Nov 18 '05 #1
4 2348
Hi Roshawn,

If you expose the fields you want to display as public properties then
one way to reach them is with the DataBinder.Eval method.

For example, imagine an array of objects of the following class class
(in C# but gives you the idea):

class Department
{
public Department(string name, string description)
{
this.name = name;
Description = description;
}

public string Name
{
get { return name; }
set { name = value; }
}

public string Description
{
get { return description; }
set { description = value; }
}

protected string name;
protected string description;

}

Then you can display them in a repeater item template using:

<%# DataBinder.Eval(Container.DataItem, "Name") %>

HTH,

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

On Fri, 6 Aug 2004 10:22:40 -0500, "Roshawn" <ud****@bellsouth.net>
wrote:
Hi,

I have a Repeater control that is databound to an array. This array
contains data regarding products (ie. Name, Price, Manufacturer, etc.).

I am wondering how do I display data in a control that is contained in the
Repeater's ItemTemplate?
Here's my example code:

Sub BindToArray()
'code for the array omitted here
Me.Repeater1.DataSource = products
Me.Repeater1.DataBind()
End Sub

<asp:Repeater>
<ItemTemplate>
<!-- say that I wanted to bind to the Name field of the array
<asp:Label id=Label1 Text=<%#
Container.DataItem("Name")%>></asp:Label>
</ItemTemplate>
</asp:Repeater>

Would this code work?

Roshawn


Nov 18 '05 #2
Thanks Scott for your .NET wisdom. That helps a lot!!!

Roshawn
Nov 18 '05 #3
Ooh, that sample class was ugly. I was experimenting with fields
versus properties. Please ignore the goofy looking destructor - I'm
glad the big concept came through.

Best of luck!

--s

On Fri, 06 Aug 2004 14:18:48 -0400, Scott Allen
<bitmask@[nospam].fred.net> wrote:
Hi Roshawn,

If you expose the fields you want to display as public properties then
one way to reach them is with the DataBinder.Eval method.

For example, imagine an array of objects of the following class class
(in C# but gives you the idea):

class Department
{
public Department(string name, string description)
{
this.name = name;
Description = description;
}

public string Name
{
get { return name; }
set { name = value; }
}

public string Description
{
get { return description; }
set { description = value; }
}

protected string name;
protected string description;

}

Then you can display them in a repeater item template using:

<%# DataBinder.Eval(Container.DataItem, "Name") %>

HTH,


--
Scott
http://www.OdeToCode.com
Nov 18 '05 #4
Oh man, I meant goofy looking CONstructor - not destructor. It's
Friday but I don't think I've had anything to drink yet!

--s

On Fri, 06 Aug 2004 17:01:43 -0400, Scott Allen
<bitmask@[nospam].fred.net> wrote:
Ooh, that sample class was ugly. I was experimenting with fields
versus properties. Please ignore the goofy looking destructor - I'm
glad the big concept came through.

Best of luck!

--s


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

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

Similar topics

3
by: DonRex | last post by:
Hello all! I couldn't find a web application-newsgroup for ASP.NET, so I'm sorry if this is the wrong forum! Synopsis: In my webform I have 3 nested repeaters: rpWeeks ----- rpTime
4
by: John Holmes | last post by:
I'm using data to rename some web controls on a form that uses a repeater contol and so it can have mulitple instances of the same control set. The controls get renamed (thanks to Steven Cheng's...
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...
9
by: Ric | last post by:
im new to asp.net. please help if u can. is it possible to refer to a control(ie lable, placeholder, textbox) that is inside a repeater object from a code behind file? when i place the control...
6
by: Zenobia | last post by:
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'...
1
by: George Durzi | last post by:
Don't know why I'm having trouble with this: Dim arNewsletters As DataRow() = dsPubs.Tables(0).Select("CategoryName = 'Newsletters'") If (arNewsletters.Length > 0) Then...
1
by: jeremystein | last post by:
With nested repeaters, how can I access the outer repeater's DataItem from the inner repeater? Here's a snippet from my aspx: <asp:repeater id="OuterRepeater" runat="server"...
1
by: Dave | last post by:
I have the following ASP.NET 2.0 code (simplified here for ease): <asp:Repeater id="SearchResultsRepeater" runat="server"> <ItemTemplate> <uc:SearchResult ID="SearchResult"...
4
by: John Kotuby | last post by:
Hi all, I am using a Repeater in conjunction with a SQLDatasource and SQL Server. One of the controls in the repeater is a HyperlLink as follows: <asp:HyperLink...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.