Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataList1.Controls(0).FindControl("PriceLabel")

Status
Not open for further replies.

wallm

Programmer
Apr 4, 2005
69
GB
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:DataList 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:DataList>


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.
 
>>How can I solve this problem?


use event bubbling. it is there in DataGrid. There is an ItemCommand event. that ought to solve your problem...

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top