Click here to Skip to main content
15,884,629 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.

thanks
Posted

Hi Ruby,

Implement your logic as below.

C#
protected void btn_Click(object sender, EventArg e)
{
   string lot_code ="";
   foreach(Item item in lstBox.Items)
   { 
      if(item.IsSelected)
        lot_code+="'"+item.SelectedItem.Text+"',";
   }
   lot_code.TrimEnd(",");

   //Execute below query to get the result from the database
   //"Select sum(cost) from tableName where lot_code IN ("+lot_code+");"
}
 
Share this answer
 
You may use something like this (error handling left to the reader)
C#
int sum = 0;
foreach (object item in myListBox.SelectedItems)
{
  DataRow [] dr =myDataTable.select("lot_code = " int.Parse(item.tostring()));
  sum += dr[0]["cost"];
}
 
Share this answer
 

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