Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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 9-Dec-12 5:39am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi Ruby,
 
Implement your logic as below.
 
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+");"
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

You may use something like this (error handling left to the reader)
int sum = 0;
foreach (object item in myListBox.SelectedItems)
{
  DataRow [] dr =myDataTable.select("lot_code = " int.Parse(item.tostring()));
  sum += dr[0]["cost"];
}
  Permalink  

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

  Print Answers RSS
0 CPallini 540
1 Sergey Alexandrovich Kryukov 420
2 George Jonsson 328
3 Pheonyx 218
4 OriginalGriff 215
0 OriginalGriff 4,813
1 CPallini 3,890
2 Sergey Alexandrovich Kryukov 3,274
3 George Jonsson 2,552
4 Gihan Liyanage 2,186


Advertise | Privacy | Mobile
Web03 | 2.8.140905.1 | Last Updated 10 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100