Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi, i had a listbox will binding the data for price of the product. How can i calculate the total price of all of it?

My phone page.xaml is as below:

XML
<ListBox Height="650" HorizontalAlignment="Left" Margin="11,17,0,0" Name="listBox1" VerticalAlignment="Top" Width="434" >
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding ProdId}"/>
                            <TextBlock Text="{Binding ProdPrice}"/>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
</ListBox>


I want to calculate all total price that at textblock that bind to Product Price and place it to a textblock.

And this is the code i retrieve data from database and put into listbox.

C#
public MainPage()
        {
            InitializeComponent();
            Service1Client svc = new Service1Client();
            svc.GetAllModelsCompleted += new EventHandler<GetAllModelsCompletedEventArgs>(svc_GetAllModelsCompleted);
            svc.GetAllModelsAsync();
        }
        void svc_GetAllModelsCompleted(object sender, GetAllModelsCompletedEventArgs e)
        {
            listBox1.ItemsSource = e.Result;
        }
Posted

1 solution

Hi try the event SelectedIndexChanged, so as to get the value and make appropriate calculation.

Regards,
T
 
Share this answer
 
Comments
hueikar 4-Jun-12 9:43am    
But how to get the value,
i had try below coding. but had error..
private void ListBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
listBox1.ApplyTemplate(); StackPanel stkTemplatedChild = VisualTreeHelper.GetChild((DependencyObject)listBox1, 0)
as StackPanel; TextBox templatedTxtBx = stkTemplatedChild.FindName("PhoneNo") as TextBox;
templatedTxtBx = lbl_PhoneNo.Text;
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900