Click here to Skip to main content
15,940,550 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
on my web form i have a multiple selection list box control in which user can select any number of lot_code, in the next text box i want to display total cost of all the selected lot_codes from sql server data table.
how can i implement this please help.

i am doing like this but it's not working.

C#
protected void lstLotBided_SelectedIndexChanged(object sender, EventArgs e)
   {
       txtsaleprice.Text = "People Records : " + lstLotBided.Items.Count.ToString();

       if ((lstLotBided.Items.Count > 0 && lstLotBided.SelectedIndex >= 0))
       {
           dt = objEmd.SelectSale_Price(lstLotBided.SelectedValue);
           double tempsaleprice = 0;
           for (int i = 0; i < lstLotBided.Items.Count; i++)
           {
               if (lstLotBided.Items[i].Selected)
               {
                   tempsaleprice = tempsaleprice + Convert.ToDouble(lstLotBided.Items[i].Text);

               }
           }
           txtsaleprice.Text = tempsaleprice.ToString();
       }
       else
       {
           txtsaleprice.Text = "";
       }
   }

any suggestions.
thanks
Posted
Updated 9-Dec-12 23:21pm
v2

1 solution

Hi
In List selected index change event you can add the total and assign to Result textbox

Thanks
Mohan
 
Share this answer
 
Comments
ruby kaur 10-Dec-12 5:19am    
i am already doing like this :

protected void lstLotBided_SelectedIndexChanged(object sender, EventArgs e)
{
txtsaleprice.Text = "People Records : " + lstLotBided.Items.Count.ToString();

if ((lstLotBided.Items.Count > 0 && lstLotBided.SelectedIndex >= 0))
{
dt = objEmd.SelectSale_Price(lstLotBided.SelectedValue);
double tempsaleprice = 0;
for (int i = 0; i < lstLotBided.Items.Count; i++)
{
if (lstLotBided.Items[i].Selected)
{
tempsaleprice = tempsaleprice + Convert.ToDouble(lstLotBided.Items[i].Text);

}
}
txtsaleprice.Text = tempsaleprice.ToString();
}
else
{
txtsaleprice.Text = "";
}
}

But it is not working. if u suggest any improvement pls make them.
thanks

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