Hi,
I have a Datagridview with Columns Product Name, Unit Price,Qty ,Total and Status. The value of Status Column will be "Y" or "N" depending upon the Product which is fetched from the database.What i need is to get the Grand total of Products with Status="Y" in Textbox1 and the Total of Products with Status="N" in TextBox2. This is what i should get,
Product Unit Price Qty Total Status
A 10 2 20.00 Y
B 20 1 20.00 N
C 50 2 100.00 Y
D 30 1 30.00 Y
E 25 1 25.00 N
TextBox1=150.00
TextBox2= 45.00
How to acheive this.Pls help and thanks in advance
Loading
VulpesPosted Apr 12, 2013, 8:38 AM
If that's the case, should we assume that it contains Y or N for the purposes of adding up the figures?
Anurag SarkarPosted Apr 12, 2013, 4:56 AM
ullas KPosted Apr 12, 2013, 4:45 AM
Gaurav GuptaPosted Apr 12, 2013, 3:22 AM
int j=0;
foreach (DataGridViewRow row in GrdCheckins.Rows)
{
status = GrdCheckins.Rows[row.Index].Cells[4].Value.ToString());
If (status=="Y")
{
i=i+Convert.ToInt32(GrdCheckins.Rows[row.Index].Cells[3].Value);
}
else if(status=="N")
{
j=j+Convert.ToInt32(GrdCheckins.Rows[row.Index].Cells[3].Value);
}
}
TextBox1=i.ToSting();
TextBox2= j.ToString();
Note: GrdCheckins is the name of the DataGridView Control.