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

playing with data within the databound repeater

*sigh*...I've asked this before, but have long forgotten the answer.

In the past, I'd often use repeater controls, bind data to it, and then
reference the data fields from within the repeater:

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

More recently, I've been doing more of the building on the codebehind side,
creating a string builder and building the table from there. When doing
that, I access the data like this:

ds.Tables(0).rows(0)("agentMobilePhone")

Both methods work fine and I see advantages and disadvantages to each.

At the moment, I'm building a table via the former...using a repeater
control. I get frustrated when I want to perform some logic on the data on
the the front-end, though.

I can't simply do this:

if DataBinder.Eval(Container.DataItem, "agentMobilePhone") = something then

as that returns a 'container' not declared error.

I can't access the DS from the front end, either:

if ds.Tables(0).rows(0)("agentMobilePhone")

as ds isn't declared.

So, when I want to do some comparison logic on data via a repeater control,
I need to make a new function on the codebehind page just for this, then
pass the data to the function.

My question is: Is there anyway to access one of the items of data in the
bound repeater from the repeater itself...without having to go back into the
codebehind?

(I know there is a way, I've just forgotten how.)

-Darrel
Nov 18 '05 #1
8 2366
You can simply hook into the ItemDataBound event and do all your processing
in there. Sure it's still in the codebehind, but it's isolated to a single
function. This is without a doubt the right way to go, you can check out
more from my tutorial on databinding:
http://openmymind.net/databinding/index.html

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"darrel" <no*****@hotmail.com> wrote in message
news:e6*************@TK2MSFTNGP11.phx.gbl...
*sigh*...I've asked this before, but have long forgotten the answer.

In the past, I'd often use repeater controls, bind data to it, and then
reference the data fields from within the repeater:

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

More recently, I've been doing more of the building on the codebehind side, creating a string builder and building the table from there. When doing
that, I access the data like this:

ds.Tables(0).rows(0)("agentMobilePhone")

Both methods work fine and I see advantages and disadvantages to each.

At the moment, I'm building a table via the former...using a repeater
control. I get frustrated when I want to perform some logic on the data on
the the front-end, though.

I can't simply do this:

if DataBinder.Eval(Container.DataItem, "agentMobilePhone") = something then
as that returns a 'container' not declared error.

I can't access the DS from the front end, either:

if ds.Tables(0).rows(0)("agentMobilePhone")

as ds isn't declared.

So, when I want to do some comparison logic on data via a repeater control, I need to make a new function on the codebehind page just for this, then
pass the data to the function.

My question is: Is there anyway to access one of the items of data in the
bound repeater from the repeater itself...without having to go back into the codebehind?

(I know there is a way, I've just forgotten how.)

-Darrel

Nov 18 '05 #2
Whatever is inside the construct will eventually wind up in a
statement like:

System.Convert.ToString(<insert your data binding expr here>)

So any expression that can return an object is fair game.

Or are you trying to reference cells in the Repeater?

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

On Tue, 30 Nov 2004 11:47:17 -0600, "darrel" <no*****@hotmail.com>
wrote:
*sigh*...I've asked this before, but have long forgotten the answer.

In the past, I'd often use repeater controls, bind data to it, and then
reference the data fields from within the repeater:

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

More recently, I've been doing more of the building on the codebehind side,
creating a string builder and building the table from there. When doing
that, I access the data like this:

ds.Tables(0).rows(0)("agentMobilePhone")

Both methods work fine and I see advantages and disadvantages to each.

At the moment, I'm building a table via the former...using a repeater
control. I get frustrated when I want to perform some logic on the data on
the the front-end, though.

I can't simply do this:

if DataBinder.Eval(Container.DataItem, "agentMobilePhone") = something then

as that returns a 'container' not declared error.

I can't access the DS from the front end, either:

if ds.Tables(0).rows(0)("agentMobilePhone")

as ds isn't declared.

So, when I want to do some comparison logic on data via a repeater control,
I need to make a new function on the codebehind page just for this, then
pass the data to the function.

My question is: Is there anyway to access one of the items of data in the
bound repeater from the repeater itself...without having to go back into the
codebehind?

(I know there is a way, I've just forgotten how.)

-Darrel


Nov 18 '05 #3
> This is without a doubt the right way to go, you can check out
more from my tutorial on databinding:
http://openmymind.net/databinding/index.html


Thanks, Karl...reading it now...

-Darrel
Nov 18 '05 #4
> Or are you trying to reference cells in the Repeater?

Right. Let's say I've bound data to the repeater and I now want to reference
the 'userID' field for that current record FROM the repeater itself (not the
codebehind) and perform some logic with it.

Can that be done?

-Darrel
Nov 18 '05 #5
Ah, yes. Karl has a good suggestion for that approach.

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

On Tue, 30 Nov 2004 13:26:12 -0600, "darrel" <no*****@hotmail.com>
wrote:
Or are you trying to reference cells in the Repeater?


Right. Let's say I've bound data to the repeater and I now want to reference
the 'userID' field for that current record FROM the repeater itself (not the
codebehind) and perform some logic with it.

Can that be done?

-Darrel


Nov 18 '05 #6
> This is without a doubt the right way to go, you can check out
more from my tutorial on databinding:
http://openmymind.net/databinding/index.html

Hmm...well, I made it about half way through, but then I got a bit lost.

Let me use a real world example. Let's say I have this:

<repeater OnItemDataBound="repeater_ItemDataBound">
<%# DataBinder.Eval(Container.DataItem, "name") %>
<%# DataBinder.Eval(Container.DataItem, "address") %>
</repeater>

How do I access the individual items via the codebehind function? I'm stuck
on the pseudo code I have below:

sub repeater(ByVal s As Object, ByVal e As RepeaterItemEventArgs)
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
ListItemType.AlternatingItem Then

'start pseudo code
if 'name'.tostring = "" then that item = "no name given"
'end pseudo code

End If
end sub
Nov 18 '05 #7
If I understand correctly, the article does cover this. Assuming you are
binding to a dataset/datatable/dataview, you'd do something like:

<itemtemplate>
<asp:literal id="name" runat="server" />
</itemtemplate>

dim nameLiteral as Literal = ctype(e.item.FindControl("name"), Literal)

dim row as DataRowView = ctype(e.Item.DataItem, DataRowView)
dim nameValue as string = cstr(row["name"])
if nameValue.length = 0 then
nameLiteral.Text = "no name given"
else
nameLiteral.Text = nameValue
end if

Keep reading :P you'll get to it :)

karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"darrel" <no*****@hotmail.com> wrote in message
news:O2**************@tk2msftngp13.phx.gbl...
This is without a doubt the right way to go, you can check out
more from my tutorial on databinding:
http://openmymind.net/databinding/index.html

Hmm...well, I made it about half way through, but then I got a bit lost.

Let me use a real world example. Let's say I have this:

<repeater OnItemDataBound="repeater_ItemDataBound">
<%# DataBinder.Eval(Container.DataItem, "name") %>
<%# DataBinder.Eval(Container.DataItem, "address") %>
</repeater>

How do I access the individual items via the codebehind function? I'm

stuck on the pseudo code I have below:

sub repeater(ByVal s As Object, ByVal e As RepeaterItemEventArgs)
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
ListItemType.AlternatingItem Then

'start pseudo code
if 'name'.tostring = "" then that item = "no name given"
'end pseudo code

End If
end sub

Nov 18 '05 #8
> If I understand correctly, the article does cover this. Assuming you are
binding to a dataset/datatable/dataview, you'd do something like:


I'm binding to a repeater.

Ah...OK, so you are replacing all the refernces to the dataitem directly
with literals.

This makes sense in the realm of separating presentation code from logic
code.

OK, I think I'm close. This is what I have (code trimmed for clarification):

ASPX:

<asp:Repeater OnItemDataBound="repeater_agentlist_ItemDataBound"
id=repeater_agentlist runat="server">
<ItemTemplate>
<asp:Literal id=literal_agentMobilePhone runat="server" />

CODEBEHIND:

sub bindData()
Dim DS As New DataSet
repeater_agentlist.DataSource = DS
repeater_agentlist.DataBind()

sub repeater_agentlist_ItemDataBound(ByVal s As Object, ByVal e As
RepeaterItemEventArgs)
dim agentMobilePhoneLiteral as Literal =
ctype(e.item.FindControl("literal_agentMobilePhone "), Literal)
dim row as DataRowView = ctype(e.Item.DataItem, DataRowView)
dim agentMobilePhone as string = cstr(row("agentMobilePhone"))
if agentMobilePhoneLiteral.tostring.length = 0 then
agentMobilePhoneLiteral.Text = ""
else
agentMobilePhoneLiteral.Text = "THIS WORKS?"
end if
end sub

Doesn't quite work. My guess is that I'm using the wrong syntax to grab data
from the dataset. Row is a part of a dataTable, correct?

Let me fiddle with this a bit more...

-Darrel
Nov 18 '05 #9

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

Similar topics

0
by: mark | last post by:
My problem is I need to have a "nested" repeater. I have an array which I load into a hashtable - that part works great. I can setup the second repeater to work just fine, as long as it's not...
4
by: Roshawn | last post by:
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...
1
by: Majek | last post by:
I have created a repeater with a linkbutton for each databound item. When I fire off the repeater controls ItemCommand event I execute the following... For indx = 0 To rpContacts.Items.Count -...
4
by: Rudy | last post by:
Hello all! I would like to take a row from a table and display this info in a nice layout. I tried the the reapeater, can't seemm to do too much with that. And I don't want a grid layout. I...
4
by: Joel | last post by:
Hey all- I'm new to asp.net so please bear with me -- I'm attempting to reference the repeater's Container.DataItem outside the repeater object. In other words -- In a seperate sub routine:...
4
by: darrel | last post by:
I have a repeater that I'd like to apply some logic to, namly highlighting the top few items in the repeater. To do this, I need to determine the record count. I've tried this: <% dim...
4
by: jjack100 | last post by:
I have a DropDownList that is nested inside a Repeater. The datasource of the DropDownList is declared in the aspx, not the codebehind. So we have this: <asp:Repeater ID="rptOptions"...
6
by: Guabble | last post by:
Hi Can anyone help me? I want to be able to show my sqldatareader contents in a gridview whereby the child data is concatenated up in a single row. Is this possible? For example Author...
1
by: mark4asp | last post by:
I have a table bound to a repeater. There is a DateTime column called EntryDate. When the EntryDate changes day I want to write the date out. I want to compare the value of an item from a table...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
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...
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
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.