title: How to perform an update using Linq or Lambda?(C#, Asp.net,Linq , Lambda)
body: <p>How can I do an update in Linq</p>
  
  <p>My code is</p>
  
  <pre><code>List&lt;Cart&gt; objNewCartItems = (List&lt;Cart&gt;)Session["CartItems"];
  
              if ((objNewCartItems != null) &amp;&amp; (objNewCartItems.Count &gt; 0))
              {
                  for (int i = 0; i &lt; dgShoppingCart.Rows.Count; i++)
                  {
                      Cart c = new Cart();
                      TextBox t = (TextBox)dgShoppingCart.Rows[i].FindControl("txtQuantity");
                      c.Quantity = (t.Text == string.Empty? (int?)null: Convert.ToInt32(t.Text));
  
                      objNewCartItems[i].Quantity = c.Quantity;
                  }
              }
              Session["CartItems"] = objNewCartItems;            
              Response.Redirect("ItemListing.aspx", false);
  </code></pre>
  
  <p>Basically in the Cart Collection, there is an item called an Quantity which will be populated when the user will fill that.</p>
  
  <p>So I am reading the Grid item and updating the Quantity attribute.</p>
  
  <p>But I am sure that there must be a better way via linq or lambda to do the same.</p>
  
  <p>Please help</p>
  
  <p>Thanks in advance</p>