asp.net Datagrid问题 [英] asp.net Datagrid issues
问题描述
我是这个发布的新手,所以......
我有一个数据网格,在一行中有一些金额,在另一行中有一个复选框.我也有一个计算按钮.当我单击计算"按钮时,我希望代码通过数据网格并计算复选框中已检查的每一行的数量,如果未选中复选框,则不应使用该数量.我很困惑,但是到目前为止我已经掌握了编码.它是通过按钮on_Click事件调用的:
hi i''m new at this posting thing so here goes...
I''ve got a datagrid with some amounts in one row and a checkbox in another. I also have a calculate button. When i click the calculate button, i want the code to go through the datagrid and calculate the amounts of each row that has been checked in the checkbox, if a checkbox is not checked, it should not use that amount. I''m stumped, but here''s the coding i''ve got so far. It''s called from the button on_Click event:
foreach (GridViewRow rows in dgServices.Rows)
{
CheckBox cb = (CheckBox)rows.FindControl"cbAddTo");
if (cb.Checked == true)
{
CalculatedItem += float.Parse(dgServices.Rows[0].Cells[8].Text);
//here''s the problem in the .Rows[0]
}
else
{
//do nothing
}
txtTB4V.Text = CalculatedItem.ToString();
}
所以基本上我需要知道我是否走在正确的轨道上,或者是否有更简单的方法来做到这一点.在此先感谢:)
[edit]添加了代码块-OriginalGriff [/edit]
so basically i need to know if i''m on the right track or if there''s an easier way to do this. Thanks in advance :)
[edit]Code block added - OriginalGriff[/edit]
推荐答案
为什么不只使用循环变量:"rows"
Why not just use the loop variable: "rows"
CalculatedItem += float.Parse(rows.Cells[8].Text);
这篇关于asp.net Datagrid问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!