473,395 Members | 1,458 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,395 software developers and data experts.

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><%#DataBinder.Eval(Container.DataItem,
"ProduitDesc") %></td>
<td>
<asp:TextBox ID="txtQteTotal">
<%#DataBinder.Eval(Container.DataItem,
"QteTotal") %>
</asp:TextBox></td>
<td><%#DataBinder.Eval(Container.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="lblGrandTotal" Visible="true"
/></td>
<td>
<asp:Label ID="lblGrandPrix" 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.EventArgs) Handles MyBase.Load
Dim dtCart As DataTable = Nothing
Dim aControl As System.Web.UI.Control

If IsNothing(Session("ContactInfo")) Then
Response.Redirect("login.aspx")
End If

If Not Page.IsPostBack Then
If Session("ShoppingCart").GetType.FullName.IndexOf(" DataTable") <>
-1 Then
dtCart = CType(Session("ShoppingCart"), DataTable)
Me.order_cart.DataSource = dtCart
Me.order_cart.DataBind()

For Each aControl In Me.order_cart.Controls
Dim theLabel As System.Web.UI.WebControls.Label

' theLabel = CType(aControl.ID .FindControl("lblGrandPrix"),
System.Web.UI.WebControls.Label)
'If Not IsNothing(theLabel) Then
' theLabel.Text = String.Format("{0:C}", sglGrandPrix)
'End If

'theLabel = CType(aControl.FindControl("lblGrandTotal"),
System.Web.UI.WebControls.Label)
'If Not IsNothing(theLabel) Then
' theLabel.Text = String.Format("{0:C}", intGrandTotal)
'End If

Next

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

End If
End Sub

Public Sub ComputeSum(ByVal sender As Object, ByVal e As
RepeaterItemEventArgs) Handles order_cart.ItemDataBound
'First, make sure we are dealing with an Item or AlternatingItem
If e.Item.ItemType = ListItemType.Item Or _
e.Item.ItemType = ListItemType.AlternatingItem Then
'Snip out the ViewCount
sglGrandPrix += Convert.ToSingle(DataBinder.Eval(e.Item.DataItem,
"PrixDetail"))
intGrandTotal += Convert.ToInt32(DataBinder.Eval(e.Item.DataItem,
"QteTotal"))

ElseIf e.Item.ItemType = ListItemType.Footer Then
End If

End Sub

Mar 28 '06 #1
2 2269
I just took fast look at the code.
<asp:TextBox ID="txtQteTotal">
<%#DataBinder.Eval(Container.DataItem,
"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.com> wrote in message
news:11*********************@g10g2000cwb.googlegro ups.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><%#DataBinder.Eval(Container.DataItem,
"ProduitDesc") %></td>
<td>
<asp:TextBox ID="txtQteTotal">
<%#DataBinder.Eval(Container.DataItem,
"QteTotal") %>
</asp:TextBox></td>
<td><%#DataBinder.Eval(Container.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="lblGrandTotal" Visible="true"
/></td>
<td>
<asp:Label ID="lblGrandPrix" 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.EventArgs) Handles MyBase.Load
Dim dtCart As DataTable = Nothing
Dim aControl As System.Web.UI.Control

If IsNothing(Session("ContactInfo")) Then
Response.Redirect("login.aspx")
End If

If Not Page.IsPostBack Then
If Session("ShoppingCart").GetType.FullName.IndexOf(" DataTable") <>
-1 Then
dtCart = CType(Session("ShoppingCart"), DataTable)
Me.order_cart.DataSource = dtCart
Me.order_cart.DataBind()

For Each aControl In Me.order_cart.Controls
Dim theLabel As System.Web.UI.WebControls.Label

' theLabel = CType(aControl.ID .FindControl("lblGrandPrix"),
System.Web.UI.WebControls.Label)
'If Not IsNothing(theLabel) Then
' theLabel.Text = String.Format("{0:C}", sglGrandPrix)
'End If

'theLabel = CType(aControl.FindControl("lblGrandTotal"),
System.Web.UI.WebControls.Label)
'If Not IsNothing(theLabel) Then
' theLabel.Text = String.Format("{0:C}", intGrandTotal)
'End If

Next

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

End If
End Sub

Public Sub ComputeSum(ByVal sender As Object, ByVal e As
RepeaterItemEventArgs) Handles order_cart.ItemDataBound
'First, make sure we are dealing with an Item or AlternatingItem
If e.Item.ItemType = ListItemType.Item Or _
e.Item.ItemType = ListItemType.AlternatingItem Then
'Snip out the ViewCount
sglGrandPrix += Convert.ToSingle(DataBinder.Eval(e.Item.DataItem,
"PrixDetail"))
intGrandTotal += Convert.ToInt32(DataBinder.Eval(e.Item.DataItem,
"QteTotal"))

ElseIf e.Item.ItemType = ListItemType.Footer 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
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...
1
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...
8
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">...
2
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: ...
73
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...
5
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....
2
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: ...
8
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...
4
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...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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...

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.