列表框的多个选定item_code的总成本 [英] total cost of list box's multiple selected item_code

查看:57
本文介绍了列表框的多个选定item_code的总成本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在我的网络表单上我有一个多选列表框控件,用户可以在其中选择任意数量的lot_code,在下一个文本框中我想显示所有选中的总成本来自sql server数据表的lot_codes。

我该如何实现这个请帮助。



谢谢

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

推荐答案

http://social.msdn .microsoft.com /论坛/ zh / winforms / thread / 96df2c84-3507-4322-a441-4c3ba2a6522b [ ^ ]


你好Ruby,



实现您的逻辑如下。



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+");"
}


您可以使用类似的东西(错误处理留给读者)

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"];
}


这篇关于列表框的多个选定item_code的总成本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆