E
Eniac
*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> </td>
<td>
<asp:Label ID="lblGrandTotal" Visible="true"
/></td>
<td>
<asp:Label ID="lblGrandPrix" Visible="true"
/></td>
<td> </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
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> </td>
<td>
<asp:Label ID="lblGrandTotal" Visible="true"
/></td>
<td>
<asp:Label ID="lblGrandPrix" Visible="true"
/></td>
<td> </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