行值的加法 [英] Addition of row values
本文介绍了行值的加法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在GridView
中取了checkbox
并成功显示了已检查的值,但我想添加该数字.
我不明白我将附加编码放在哪里,那是什么?
I have taken checkbox
within GridView
and succeeded to display the checked value but i want to add that numbers.
I can''t understand where will I put addition coding and what is that?
StringBuilder str = new StringBuilder();
// Select the checkboxes from the GridView control
for (int i = 0; i < GridView2.Rows.Count; i++)
{
GridViewRow row = GridView2.Rows[i];
bool isChecked = ((CheckBox)row.FindControl("CheckBox1")).Checked;
if (isChecked)
{
// Column 1 is the "Rate" column of price
str.Append(GridView2.Rows[i].Cells[1].Text);
}
}
// prints out the result
Response.Write(str.ToString());
推荐答案
从您的问题中还不清楚您遇到了什么问题-我认为英语不是您的母语?因此,我必须做出一些假设:
1)您有一个GridView,它显示两列或更多列.
2)其中之一是一个复选框,称为"CheckBox1",并且用户(或您的代码)检查某些CheckBoxes,而不检查其他CheckBoxes.
3)如果选中了CheckBox,则将Rate列的值(第1列,或GridView中的第二列)包括在运行总计中.
如果正确,则:
It isn''t too clear from your question what problem you are having - I assume that English is not your native language? So, I will have to make some assumptions:
1) You have a GridView, which displays two or more columns.
2) One of these is a Checkbox, called "CheckBox1", and the user (or your code) checks some CheckBoxes, and not others.
3) If a CheckBox is checked, include the value of the Rate column (Column 1, or the second column in the GridView) in a running total.
If this is correct, then:
// Select the checkboxes from the GridView control
int totalRate = 0;
for (int i = 0; i < GridView2.Rows.Count; i++)
{
GridViewRow row = GridView2.Rows[i];
bool isChecked = ((CheckBox)row.FindControl("CheckBox1")).Checked;
if (isChecked)
{
// Column 1 is the "Rate" column of price
totalRate += int.Parse(GridView2.Rows[i].Cells[1].Text);
}
}
// prints out the result
Response.Write(totalRate.ToString());
您可能需要将int
更改为另一种数据类型-如果这样,请不要忘记在两个地方都进行更改!
如果这不正确,那么您要做什么?
You may need to change the int
to another data type - if so do not forget to change in in both places!
If this is not correct, then what are you trying to do?
这篇关于行值的加法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文