Manawoba michael

Manawoba michael

  • NA
  • 10
  • 2.9k

comparing gridview column values with sql table column value

Mar 19 2019 8:12 AM
i want to compare gridview column values with sql server table column values and if the values from the database is less than the gridview values the gridview row backcolor will change to black but when greater than gridview values backcolor will be red.
 
below is my c# code behind thanks in advance for your answers.
  1. public void CheckStock()  
  2. {  
  3. int DBQuantity =0;  
  4. foreach (GridViewRow row in gvCartItems.Rows)  
  5. {  
  6. for (int i = 0; i <= gvCartItems.Rows.Count; i++)  
  7. {  
  8. con = new ConnectionClass();  
  9. String pid = gvCartItems.Rows[i].Cells[1].Text;  
  10. string gvQty = gvCartItems.Rows[i].Cells[4].Text;  
  11. dr = con.DataReader("SELECT Quantity FROM ProducesView WHERE ProduceId = '" + pid + "'");  
  12. if (dr.Read())  
  13. {  
  14. DBQuantity = dr.GetInt32(0);  
  15. dr.Close();  
  16. }  
  17. int gridQty;  
  18. int.TryParse(gvQty, out gridQty);  
  19. if (DBQuantity > gridQty)  
  20. {  
  21. gvCartItems.Rows[i].BackColor = System.Drawing.Color.Black;  
  22. }  
  23. con.CloseConnection();  
  24. }  
  25. }  
  26. }  

Attachment: Screenshot_(25).zip

Answers (1)