473,890 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple task make difficult with a repeater

*argh* ... *pull hairs*

I've recently started developing from ASP to ASP.NET

The switch was fairly smooth since i had done some VB.net before ...
then came...FORMS! :)

I find it astounding at how difficult it has become to control a form,
something that was so dead easy in ASP.

Look, its simple, I've made something very basic. I created a small
datatable in session to act as a shopping cart. whenever i on my
shopping basket page, I want to create a list of all the items in the
cart with the quantity in a textbox so they can change it. two
buttons/links on each row to update / delete then at the end, a sum of
all items to be ordered and the total price.

I'm going to show the latest version of my code but I've tried several
ways already and it seems that the repeater just wont see my controls.
..... here, let me paste this code...

can PLEASE anyone tell me what im doing wrong ? any example I've found
on the web thius far only shows how to display bare data but i can do
pretty easily, its adding controls and responding to them that seems to
be difficult.

(might as well ask the next question in line...)
if thats not the way to go, what would be the way to go.

i know the repeater doesnt support the ItemCommand event thing, how
will i know which "update" or "delete" button was clicked ?

Thanks a bunch!

-----------------
<asp:Repeater ID="order_cart " Runat="server"
OnItemDataBound ="ComputeSum " Visible="True">
<HeaderTemplate >
<table width="800" cellpadding="0" cellspacing="0" >
<tr>
<th>
Description</th>
<th>
Quantité</th>
<th>
Prix</th>
<th>
Action</th>
</tr>
</HeaderTemplate>
<ItemTemplate >
<tr>
<td><%#DataBind er.Eval(Contain er.DataItem,
"ProduitDes c") %></td>
<td>
<asp:TextBox ID="txtQteTotal ">
<%#DataBinder.E val(Container.D ataItem,
"QteTotal") %>
</asp:TextBox></td>
<td><%#DataBind er.Eval(Contain er.DataItem,
"PrixDetail ") %></td>
<td>
<asp:Button ID="btnUpdate" Text="Mise à jour" />
<asp:Button ID="btnDelete" Text="Supprimer " />
</td>
</tr>
</ItemTemplate>
<FooterTemplate >
<tr>
<td>&nbsp;</td>
<td>
<asp:Label ID="lblGrandTot al" Visible="true"
/></td>
<td>
<asp:Label ID="lblGrandPri x" Visible="true"
/></td>
<td>&nbsp;</td>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>
------------------

then in the code behind...

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim dtCart As DataTable = Nothing
Dim aControl As System.Web.UI.C ontrol

If IsNothing(Sessi on("ContactInfo ")) Then
Response.Redire ct("login.aspx" )
End If

If Not Page.IsPostBack Then
If Session("Shoppi ngCart").GetTyp e.FullName.Inde xOf("DataTable" ) <>
-1 Then
dtCart = CType(Session(" ShoppingCart"), DataTable)
Me.order_cart.D ataSource = dtCart
Me.order_cart.D ataBind()

For Each aControl In Me.order_cart.C ontrols
Dim theLabel As System.Web.UI.W ebControls.Labe l

' theLabel = CType(aControl. ID .FindControl("l blGrandPrix"),
System.Web.UI.W ebControls.Labe l)
'If Not IsNothing(theLa bel) Then
' theLabel.Text = String.Format(" {0:C}", sglGrandPrix)
'End If

'theLabel = CType(aControl. FindControl("lb lGrandTotal"),
System.Web.UI.W ebControls.Labe l)
'If Not IsNothing(theLa bel) Then
' theLabel.Text = String.Format(" {0:C}", intGrandTotal)
'End If

Next

Else
Throw New Exception("Cett e page requiert une session")
End If

End If
End Sub

Public Sub ComputeSum(ByVa l sender As Object, ByVal e As
RepeaterItemEve ntArgs) Handles order_cart.Item DataBound
'First, make sure we are dealing with an Item or AlternatingItem
If e.Item.ItemType = ListItemType.It em Or _
e.Item.ItemType = ListItemType.Al ternatingItem Then
'Snip out the ViewCount
sglGrandPrix += Convert.ToSingl e(DataBinder.Ev al(e.Item.DataI tem,
"PrixDetail "))
intGrandTotal += Convert.ToInt32 (DataBinder.Eva l(e.Item.DataIt em,
"QteTotal") )

ElseIf e.Item.ItemType = ListItemType.Fo oter Then
End If

End Sub

Mar 28 '06 #1
2 2291
I just took fast look at the code.
<asp:TextBox ID="txtQteTotal ">
<%#DataBinder.E val(Container.D ataItem,
"QteTotal") %>
</asp:TextBox></

this will never work.
first of all you need to make sure that you have runat=server if you want
asp.net to process it.
2) TextBox has Text property that you must use.
3) you won't be able to set the value of most asp control using inline
databindings in repeater. you must handle ItemDataBound event for it.

Good luck.
"Eniac" <En****@gmail.c om> wrote in message
news:11******** *************@g 10g2000cwb.goog legroups.com...
*argh* ... *pull hairs*

I've recently started developing from ASP to ASP.NET

The switch was fairly smooth since i had done some VB.net before ...
then came...FORMS! :)

I find it astounding at how difficult it has become to control a form,
something that was so dead easy in ASP.

Look, its simple, I've made something very basic. I created a small
datatable in session to act as a shopping cart. whenever i on my
shopping basket page, I want to create a list of all the items in the
cart with the quantity in a textbox so they can change it. two
buttons/links on each row to update / delete then at the end, a sum of
all items to be ordered and the total price.

I'm going to show the latest version of my code but I've tried several
ways already and it seems that the repeater just wont see my controls.
..... here, let me paste this code...

can PLEASE anyone tell me what im doing wrong ? any example I've found
on the web thius far only shows how to display bare data but i can do
pretty easily, its adding controls and responding to them that seems to
be difficult.

(might as well ask the next question in line...)
if thats not the way to go, what would be the way to go.

i know the repeater doesnt support the ItemCommand event thing, how
will i know which "update" or "delete" button was clicked ?

Thanks a bunch!

-----------------
<asp:Repeater ID="order_cart " Runat="server"
OnItemDataBound ="ComputeSum " Visible="True">
<HeaderTemplate >
<table width="800" cellpadding="0" cellspacing="0" >
<tr>
<th>
Description</th>
<th>
Quantité</th>
<th>
Prix</th>
<th>
Action</th>
</tr>
</HeaderTemplate>
<ItemTemplate >
<tr>
<td><%#DataBind er.Eval(Contain er.DataItem,
"ProduitDes c") %></td>
<td>
<asp:TextBox ID="txtQteTotal ">
<%#DataBinder.E val(Container.D ataItem,
"QteTotal") %>
</asp:TextBox></td>
<td><%#DataBind er.Eval(Contain er.DataItem,
"PrixDetail ") %></td>
<td>
<asp:Button ID="btnUpdate" Text="Mise à jour" />
<asp:Button ID="btnDelete" Text="Supprimer " />
</td>
</tr>
</ItemTemplate>
<FooterTemplate >
<tr>
<td>&nbsp;</td>
<td>
<asp:Label ID="lblGrandTot al" Visible="true"
/></td>
<td>
<asp:Label ID="lblGrandPri x" Visible="true"
/></td>
<td>&nbsp;</td>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>
------------------

then in the code behind...

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim dtCart As DataTable = Nothing
Dim aControl As System.Web.UI.C ontrol

If IsNothing(Sessi on("ContactInfo ")) Then
Response.Redire ct("login.aspx" )
End If

If Not Page.IsPostBack Then
If Session("Shoppi ngCart").GetTyp e.FullName.Inde xOf("DataTable" ) <>
-1 Then
dtCart = CType(Session(" ShoppingCart"), DataTable)
Me.order_cart.D ataSource = dtCart
Me.order_cart.D ataBind()

For Each aControl In Me.order_cart.C ontrols
Dim theLabel As System.Web.UI.W ebControls.Labe l

' theLabel = CType(aControl. ID .FindControl("l blGrandPrix"),
System.Web.UI.W ebControls.Labe l)
'If Not IsNothing(theLa bel) Then
' theLabel.Text = String.Format(" {0:C}", sglGrandPrix)
'End If

'theLabel = CType(aControl. FindControl("lb lGrandTotal"),
System.Web.UI.W ebControls.Labe l)
'If Not IsNothing(theLa bel) Then
' theLabel.Text = String.Format(" {0:C}", intGrandTotal)
'End If

Next

Else
Throw New Exception("Cett e page requiert une session")
End If

End If
End Sub

Public Sub ComputeSum(ByVa l sender As Object, ByVal e As
RepeaterItemEve ntArgs) Handles order_cart.Item DataBound
'First, make sure we are dealing with an Item or AlternatingItem
If e.Item.ItemType = ListItemType.It em Or _
e.Item.ItemType = ListItemType.Al ternatingItem Then
'Snip out the ViewCount
sglGrandPrix += Convert.ToSingl e(DataBinder.Ev al(e.Item.DataI tem,
"PrixDetail "))
intGrandTotal += Convert.ToInt32 (DataBinder.Eva l(e.Item.DataIt em,
"QteTotal") )

ElseIf e.Item.ItemType = ListItemType.Fo oter Then
End If

End Sub
Mar 28 '06 #2
Hum, thanks, i probably would've found that one sooner or later. i know
about the runat=server, for some reason i just forgot about it when i
wrote it. and the <% %> was not in the text attribute because it messes
up the designer.

Let me put it another way.

Can someone give me a hint on how to display a bunch of rows with
controls associated to them, surely there's a simple way no ? I have to
stick with built-in web forms control, no custom stuff.

Thanks again.

Mar 28 '06 #3

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

Similar topics

0
5408
by: Ed Allan | last post by:
http://ejaconsulting.com/nestedrepeater/NestedRepeater.txt >-----Original Message----- >Doh! The HTML has all been rendered . . . > >Right click on this link and select 'Save target as ..' >to get the code in a text file. > >Thanks - Ed >
1
1752
by: timmso | last post by:
I am trying to build a simple asp.net project. What sort of control do I need to use to simply display a list of links in a table format? For example, let's say I have a database table: tblNames ID Name 1 Blue 2 Grey 3 Green
8
2923
by: I am Sam | last post by:
Hi everyone, This problem is making me old. I don't want to get any older. I have a multi-nested repeater control as follows: <asp:Repeater ID="clubRep1" Runat="server"> <HeaderTemplate><table> </HeaderTemplate> <ItemTemplate>
2
1922
by: GD | last post by:
I'd like to use a Repeater to display data coming back from a cross-tab report. Because it's a cross-tab, I generally don't know how many columns are coming back. They do follow a certain format: e.g. CompanyName, c1, c2, c3, etc .. The current format of my repeater is: <table> <asp:Repeater ID="rptCompanies" Runat="server">
73
4666
by: Claudio Grondi | last post by:
In the process of learning about some deeper details of Python I am curious if it is possible to write a 'prefix' code assigning to a and b something special, so, that Python gets trapped in an endless loop in a line with: if a==b: print 'OK' I mean, it would be of much help to me on my way to understanding Python to know how such prefix code leading to an endless loop can look like and if it is eventually not possible to write such...
5
1402
by: Jaybuffet | last post by:
a custom object. Similar to how I bind a collection of objects to a repeater. Is there a way to bind a single object to a Table? I could use a repeater, but seems over kill for a single object. Thanks for any help.
2
1467
by: Not Me | last post by:
Hi, Yet another error that should be easy to fix.. I have a datalist linked to an sqldatasource, and I'm wanting to fill it with data from that source. The following works fine: <ItemTemplate> <asp:hyperlink runat="server" ID="hlemail" Text='<%# eval("") %>' navigateurl='<%# eval("") %>'/> </ItemTemplate>
8
3034
by: fernandezr | last post by:
I would like to use a user control as a template inside a repeater. Some of the fields in the control should be hidden depending on whether or not there is data. I'm still a ASP .Net newbie so the way I'm going about doing this might be a little off. I'd appreciate some help. Below is the code I have thus far but I'm not sure how to reference the user control within the foreach loop. <asp:Panel ID="pnlRosterProfile" runat="Server" />
4
1344
by: Laserson | last post by:
Hi all! I have a very difficult task for me and i can't so it. My task: I have created an application. But how to determine that it is not responding??? You can see it when windows add "Not Responding" to application title, but how to catch it from application? I hope you'll help...
0
9975
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, 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...
0
11212
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10799
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 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...
1
10899
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,...
0
10446
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 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...
0
9614
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, 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...
1
8004
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 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...
0
5832
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6032
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.