Hello
I have a Gridview

I have Click Button and two labels. (Risk_label and MV_label)
Risk and MV column has price value.
My Checkbox column names are NameCheckBoxField1 and NameCheckBoxField2
How can i calculate only "Which i selected in Gridview" Risk total and MV total in my labels?
Example;
C#
Risk (Checked rows) --> 10, 20, 30 ---> Risk_label = 60
MV (Checked rows) --> 20, 30, 40 ---> MV_label = 90EDIT: I try this code;
C#
double sum = 0;
foreach (GridViewRow gvr in GridView1.Rows)
{
CheckBox cb = (CheckBox)gvr.FindControl("NameCheckBoxField1");
if (cb.Checked)
{
double amount = Convert.ToDouble(gvr.Cells[1].Text);
sum += amount;
}
}
Risk_label.Text = sum.ToString();But i getting an error.

VulpesRank #55 · 29.2K reputationPosted Mar 24, 2011, 5:42 AM EDT
The checkbox appears to be in the 9th cell of the row so I'd try to get it by index instead:
Suthish NairRank #92 · 22.8K reputationPosted Mar 24, 2011, 7:57 AM EDT