我有一个复选框列表,我可以在其中设置特定项目的每个进程的百分比 这里我在复选框列表中有3个进程 包装20% Sanatising 10% 染色5%,项目用10.00
所以,如果我从复选框列表中选择多个进程 我需要得到项目的总价值
我的代码就像这样
if (cblTaskDetails.Items.Cast<ListItem>().Any(item => item.Selected))
{
for (int i = 0; i < cblTaskDetails.Items.Count; i++)
{
if (cblTaskDetails.Items[i].Selected)
{
foreach (ListItem item in cblTaskDetails.Items)
{
if (item.Selected)
{
string selectedValue = item.Value;
DataTable dt = tdbll.GetPercent(selectedValue);
foreach (DataRow dr in dt.Rows)
{
percent = Convert.ToInt32(dr["PricePercent"].ToString());
value = (percent * Convert.ToDecimal(txtRate.Text)) / 100;
}
}
}
txtRate.Text = (Convert.ToDecimal(value + Convert.ToDecimal(txtRate.Text))).ToString();
txtAmount.Text = (Convert.ToDecimal(txtQuantity.Text) * Convert.ToDecimal(txtRate.Text)).ToString();
}
}
答案 0 :(得分:0)
if (cblTaskDetails.Items.Cast<ListItem>().Any(item => item.Selected))
{
foreach (ListItem item in cblTaskDetails.Items)
{
if (item.Selected)
{
string selectedValue = item.Value;
DataTable dt = tdbll.GetPercent(selectedValue);
foreach (DataRow dr in dt.Rows)
{
percent = Convert.ToInt32(dr["PricePercent"].ToString());
value += (percent * Convert.ToDecimal(txtRate.Text)) / 100;
}
}
}
txtRate.Text = (Convert.ToDecimal(value + Convert.ToDecimal(txtRate.Text))).ToString();
txtAmount.Text = (Convert.ToDecimal(txtQuantity.Text) * Convert.ToDecimal(txtRate.Text)).ToString();
}