Hi all,
Thanks in advance for any suggestions...
I am using a repeater to display the contents of a DataTable which is bound
to it. All the rows in the table are being displayed. In the OnItemDataBound
event controller in the Code Behind I am formatting the fields returned from
the SQL server select query. The items are formatting correctly, except for
those in the last row of the bound table. To test my theory, I added a row
to the result set, with data that is nearly identical to the row that was
not being formatted. As I expected, the next-to-last row is now being
formatted properly, but the newly added row is not.
Here is the code I am using. Can anyone tell me why the last row of data is
being ignored?
I am defining the format of just the ItemTemplate in the Repeater
declaration HTML.
Note, I am iterating through the RepeaterItemCollection because that is a
code example I saw in a newsgroup and it is the only way I could get at the
particular label (so far). I am guessing there must be a simpler way to get
to a particular label control without searching the entire collection in
the repeater, but I haven't found that code example yet.
--------------------------------
Sub RepSeg_DataBound(ByVal Sender As Object, ByVal e As
RepeaterItemEventArgs)
' This event is raised for the header, the footer, separators, and items.
Dim lblCostFld As Label
Dim rc As RepeaterItemCollection = RepeaterSeg.Items
' Execute the following logic for Items and Alternating Items.
If (e.Item.ItemType = ListItemType.Item) Or _
(e.Item.ItemType = ListItemType.AlternatingItem) Then
For Each Item As RepeaterItem In rc
lblCostFld = CType(Item.FindControl("lblCost"), Label)
If Not lblCostFld Is Nothing Then
segCost = RTrim(lblCostFld.Text)
segCost = Replace(segCost, "/", "")
segCost = Replace(segCost, "M", "")
segCost = FormatCurrency(segCost)
lblCostFld.Text = segCost & "/M"
Else
'*** JPK Debug ***
Response.Write("lblCost field not found")
Response.End()
'*** JPK Debug ***
End If
Next
End If
End Sub 2 2360
Get rid of the For Each loop, it doesn't make any sense here. ItemDataBound
event is fired for every item, you don't need to go through all previous
items over and over again.Get to the label as e.Item.FindControl("lblCost").
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET] http://msmvps.com/blogs/egoldin http://usableasp.net
"John Kotuby" <jo***@powerlist.comwrote in message
news:Oq*************@TK2MSFTNGP05.phx.gbl...
Hi all,
Thanks in advance for any suggestions...
I am using a repeater to display the contents of a DataTable which is
bound to it. All the rows in the table are being displayed. In the
OnItemDataBound event controller in the Code Behind I am formatting the
fields returned from the SQL server select query. The items are formatting
correctly, except for those in the last row of the bound table. To test my
theory, I added a row to the result set, with data that is nearly
identical to the row that was not being formatted. As I expected, the
next-to-last row is now being formatted properly, but the newly added row
is not.
Here is the code I am using. Can anyone tell me why the last row of data
is being ignored?
I am defining the format of just the ItemTemplate in the Repeater
declaration HTML.
Note, I am iterating through the RepeaterItemCollection because that is a
code example I saw in a newsgroup and it is the only way I could get at
the particular label (so far). I am guessing there must be a simpler way
to get to a particular label control without searching the entire
collection in the repeater, but I haven't found that code example yet.
--------------------------------
Sub RepSeg_DataBound(ByVal Sender As Object, ByVal e As
RepeaterItemEventArgs)
' This event is raised for the header, the footer, separators, and items.
Dim lblCostFld As Label
Dim rc As RepeaterItemCollection = RepeaterSeg.Items
' Execute the following logic for Items and Alternating Items.
If (e.Item.ItemType = ListItemType.Item) Or _
(e.Item.ItemType = ListItemType.AlternatingItem) Then
For Each Item As RepeaterItem In rc
lblCostFld = CType(Item.FindControl("lblCost"), Label)
If Not lblCostFld Is Nothing Then
segCost = RTrim(lblCostFld.Text)
segCost = Replace(segCost, "/", "")
segCost = Replace(segCost, "M", "")
segCost = FormatCurrency(segCost)
lblCostFld.Text = segCost & "/M"
Else
'*** JPK Debug ***
Response.Write("lblCost field not found")
Response.End()
'*** JPK Debug ***
End If
Next
End If
End Sub
Thank you Eliyahu,
Your suggestion fixed the problem and streamlined the code. I appreciate the
syntax lesson....
"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:ee**************@TK2MSFTNGP02.phx.gbl...
Get rid of the For Each loop, it doesn't make any sense here.
ItemDataBound event is fired for every item, you don't need to go through
all previous items over and over again.Get to the label as
e.Item.FindControl("lblCost").
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET] http://msmvps.com/blogs/egoldin http://usableasp.net
"John Kotuby" <jo***@powerlist.comwrote in message
news:Oq*************@TK2MSFTNGP05.phx.gbl...
>Hi all,
Thanks in advance for any suggestions...
I am using a repeater to display the contents of a DataTable which is bound to it. All the rows in the table are being displayed. In the OnItemDataBound event controller in the Code Behind I am formatting the fields returned from the SQL server select query. The items are formatting correctly, except for those in the last row of the bound table. To test my theory, I added a row to the result set, with data that is nearly identical to the row that was not being formatted. As I expected, the next-to-last row is now being formatted properly, but the newly added row is not.
Here is the code I am using. Can anyone tell me why the last row of data is being ignored?
I am defining the format of just the ItemTemplate in the Repeater declaration HTML.
Note, I am iterating through the RepeaterItemCollection because that is a code example I saw in a newsgroup and it is the only way I could get at the particular label (so far). I am guessing there must be a simpler way to get to a particular label control without searching the entire collection in the repeater, but I haven't found that code example yet.
-------------------------------- Sub RepSeg_DataBound(ByVal Sender As Object, ByVal e As RepeaterItemEventArgs) ' This event is raised for the header, the footer, separators, and items. Dim lblCostFld As Label Dim rc As RepeaterItemCollection = RepeaterSeg.Items ' Execute the following logic for Items and Alternating Items.
If (e.Item.ItemType = ListItemType.Item) Or _ (e.Item.ItemType = ListItemType.AlternatingItem) Then
For Each Item As RepeaterItem In rc lblCostFld = CType(Item.FindControl("lblCost"), Label) If Not lblCostFld Is Nothing Then segCost = RTrim(lblCostFld.Text) segCost = Replace(segCost, "/", "") segCost = Replace(segCost, "M", "") segCost = FormatCurrency(segCost) lblCostFld.Text = segCost & "/M" Else '*** JPK Debug *** Response.Write("lblCost field not found") Response.End() '*** JPK Debug *** End If Next
End If
End Sub This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: az bij |
last post by:
Hi,
I have a dataset bound to a repeater and want to place some logic in
my ascx file. I want to display an image link if and only if an image
is available.
I have tried without success...
|
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: ric carrasquilla |
last post by:
first, thx to martin for helping me with my initial post. im a newbie
and appreciate the help.
if someone can help me with another question, please do.
i have a repeater pulling job...
|
by: Zenobia |
last post by:
How do I bind an array, arrayList or even a stack to a repeater
containing hyperlinks.
The data structure (array, arrayList or even a stack) has dates
in ISO format "YYYY-MM-DD". The repeated...
|
by: djc |
last post by:
I don't know why I'm getting this error? This is my first time using a
repeater and the Container.DataItem code. It looks to me like I'm doing
exactly what the examples I've looked at are doing.
...
|
by: ibiza |
last post by:
Hi all,
I have a simple scenario where I simply bien a repeater to a
datasource. Here's my repeater definition :
<asp:Repeater id="rTitles" runat="server" EnableViewState="false"...
|
by: Eric |
last post by:
Hello,
I have a repeater control bound to an XmlDataSource. Works great.
Now, I want to handle the ItemDataBound event--the e.Item.DataItem object in
particular. Its type is...
|
by: champ.supernova |
last post by:
I have a repeater containing dropdownlists. This subroutine is called
when the selected index on one of these dropdownlists is changed...
Public Sub cmbProductType_SelectedIndexChanged(ByVal...
|
by: adiel_g |
last post by:
I am trying to loop through a repeater to retrieve a dataitem field
but am getting a NullReferenceException.
I can find a checkbox control but cannot find a dataitem field. Here
is the code that...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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: 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,...
|
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...
|
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...
|
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...
| |