Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - Accessing array data with Repeater

 
Thread Tools Search this Thread
Old 08-06-2004, 04:22 PM   #1
Default 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




Roshawn
  Reply With Quote
Old 08-06-2004, 07:18 PM   #2
Scott Allen
 
Posts: n/a
Default Re: Accessing array data with Repeater
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" <>
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
>




Scott Allen
  Reply With Quote
Old 08-06-2004, 08:59 PM   #3
Roshawn
 
Posts: n/a
Default Re: Accessing array data with Repeater
Thanks Scott for your .NET wisdom. That helps a lot!!!

Roshawn




Roshawn
  Reply With Quote
Old 08-06-2004, 10:01 PM   #4
Scott Allen
 
Posts: n/a
Default Re: Accessing array data with Repeater
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


Scott Allen
  Reply With Quote
Old 08-07-2004, 12:51 AM   #5
Scott Allen
 
Posts: n/a
Default Re: Accessing array data with Repeater
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


Scott Allen
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Wonderful data input with web reporting tool freezea Software 0 09-09-2009 05:30 AM
ASP.Net - Data Repeater vbnetman General Help Related Topics 0 01-07-2008 11:34 AM
Re: HDD Data Recovery Glenn A+ Certification 0 08-29-2006 04:01 PM
Address Bus and External Data Bus Confusion LoXodonte A+ Certification 1 04-18-2006 10:09 PM
Re: Backing up data to reinstall or replace a Operating system? Barry Watzman A+ Certification 0 08-21-2003 06:59 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46