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.Da taSource = products
Me.Repeater1.Da taBind()
End Sub
<asp:Repeater >
<ItemTemplate >
<!-- say that I wanted to bind to the Name field of the array
<asp:Label id=Label1 Text=<%#
Container.DataI tem("Name")%>></asp:Label>
</ItemTemplate>
</asp:Repeater>
Would this code work?
Roshawn 4 2376
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(stri ng 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.Data Item, "Name") %>
HTH,
--
Scott http://www.OdeToCode.com
On Fri, 6 Aug 2004 10:22:40 -0500, "Roshawn" <ud****@bellsou th.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.Da taSource = products Me.Repeater1.Da taBind() End Sub
<asp:Repeate r> <ItemTemplate > <!-- say that I wanted to bind to the Name field of the array <asp:Label id=Label1 Text=<%# Container.Data Item("Name")%>> </asp:Label> </ItemTemplate> </asp:Repeater>
Would this code work?
Roshawn
Thanks Scott for your .NET wisdom. That helps a lot!!!
Roshawn
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(stri ng 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.Data Item, "Name") %>
HTH,
--
Scott http://www.OdeToCode.com
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
|
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 help) in a click event of the
button that is pushed to enter data. Each time the button is clicked it
sends the ID entered by the user to query the database and return
information. The renamed controls then include the ID in the name of the...
|
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 bind that to the
datagrid? I have never done either (usually I get a recordset from a
stored procedure and bind results directly). I also don't know which is
faster. Whichever you suggest, can you give a couple lines of sample code?
Thank...
|
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 object outside of the repeater, i can refer to it from the
code behind file. when i place the control object inside the repeater,
i get a 'need to instanciate the control object' error. if i declare
the control object inside the control behind file,...
|
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' is
| |
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
rptNewsletters.DataSource = arNewsletters
rptNewsletters.DataBind()
End If
The code compiles, but if (for the sake of example) my Repeater looks like
|
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"
onItemDataBound="PrepareInner">
<ItemTemplate>
<h1>
<%# DataBinder.Eval(Container.DataItem, "number") %>
|
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"
ResultObject="<%#Container.DataItem%>" runat="server">
<ButtonsTemplate>
<uc:ViewButton ID="ViewButton"
ListingReference='<%#Eval("ListingReference")%>' runat="server" />
</ButtonsTemplate>
|
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 NavigateUrl='Search.aspx?page=base&searchid=<%
Eval("sequence")%>' .....
As you can see I am trying to pass a QueryString evaluated at runtime. All
the other Evals of DataFields in the Repeater are working just fine. However
this NavigateUrl is resolving as...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |