I’ve removed some of the code to make this easier to read.
Below I have a datalist that displays multiple label controls that will store the prices of a shopping cart item.
When the imagebutton ‘ImageButton2” is clicked the event handler in the code behind file is raised. The problem is that every item that is displayed returns the same price as the line Double.Parse(CType(DataList1.Controls(0).FindControl("PriceLabel"), Label).Text) doesn’t differentiate or know which control was clicked.
<asp
ataList ID="DataList1" runat="server" DataKeyField="ProductID" DataSourceID="SqlDataSource1"
RepeatColumns="4" RepeatDirection="Horizontal" Width="500px">
<ItemTemplate>
<div>
<asp:Label ID="PriceLabel" runat="server" Text='<%# Eval("Price", "{0:##0.00}") %>'></asp:Label>
<asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/Images/add_to_shopping_list.gif" OnClick="ImageButton2_Click" />
</div>
</ItemTemplate>
<ItemStyle Width="125px" />
</asp
ataList>
Protected Sub ImageButton2_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
Dim Price As String = Double.Parse(CType(DataList1.Controls(0).FindControl("PriceLabel"), Label).Text)
End Sub
How can I solve this problem?
thanks,
Michael.
Below I have a datalist that displays multiple label controls that will store the prices of a shopping cart item.
When the imagebutton ‘ImageButton2” is clicked the event handler in the code behind file is raised. The problem is that every item that is displayed returns the same price as the line Double.Parse(CType(DataList1.Controls(0).FindControl("PriceLabel"), Label).Text) doesn’t differentiate or know which control was clicked.
<asp
RepeatColumns="4" RepeatDirection="Horizontal" Width="500px">
<ItemTemplate>
<div>
<asp:Label ID="PriceLabel" runat="server" Text='<%# Eval("Price", "{0:##0.00}") %>'></asp:Label>
<asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/Images/add_to_shopping_list.gif" OnClick="ImageButton2_Click" />
</div>
</ItemTemplate>
<ItemStyle Width="125px" />
</asp
Protected Sub ImageButton2_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
Dim Price As String = Double.Parse(CType(DataList1.Controls(0).FindControl("PriceLabel"), Label).Text)
End Sub
How can I solve this problem?
thanks,
Michael.