title: (ASP.NET - C#) Having problems with storing textbox.text in a listview to a datatable
body: <p>I'm trying to save the data inputted in the textboxes after clicking linkbutton <code>lnkUpdate</code>. When i click <code>lnkupdate</code>, it seems that there is no change in the datatable.</p>
  
  <p>aspx code</p>
  
  <pre><code>&lt;div class="col-md-7"&gt;
                  &lt;div class="well well-sm"&gt;
                      &lt;fieldset&gt;
                          &lt;legend&gt;Warehouse&lt;/legend&gt;
                          &lt;div class="container-fluid"&gt;
                              &lt;div class="panel panel-default"&gt;
                                  &lt;table class="table table-bordered table-hover table-responsive"&gt;
                                      &lt;thead&gt;
                                          &lt;tr&gt;
                                              &lt;td&gt;&lt;strong&gt;#&lt;/strong&gt;&lt;/td&gt;                                        
                                              &lt;td&gt;&lt;strong&gt;BranchName&lt;/strong&gt;&lt;/td&gt;
                                              &lt;td&gt;&lt;strong&gt;Quantity&lt;/strong&gt;&lt;/td&gt;
                                              &lt;td&gt;&lt;strong&gt;Critical Level&lt;/strong&gt;&lt;/td&gt;
                                              &lt;td&gt;&lt;/td&gt;
                                          &lt;/tr&gt;
                                      &lt;/thead&gt;
                                      &lt;tbody&gt;
                                      &lt;asp:ListView ID="lvWarehouse" runat="server" 
                                              onitemediting="lvWarehouse_ItemEditing" 
                                              onitemcanceling="lvWarehouse_ItemCanceling" 
                                              onitemupdating="lvWarehouse_ItemUpdating"&gt;
                                          &lt;ItemTemplate&gt;
                                              &lt;tr&gt;
                                                  &lt;td&gt;&lt;%# Eval("BranchID") %&gt;&lt;/td&gt;
                                                  &lt;td&gt;&lt;%# Eval("BranchName") %&gt;&lt;/td&gt;
                                                  &lt;td&gt;&lt;%# Eval("Quantity") %&gt;&lt;/td&gt;
                                                  &lt;td&gt;&lt;%# Eval("CriticalLevel") %&gt;&lt;/td&gt;
                                                  &lt;td&gt;
                                                      &lt;asp:LinkButton ID="btnEdit" runat="server" class="glyphicon glyphicon-pencil" CommandName="Edit" /&gt;
                                                  &lt;/td&gt;
                                              &lt;/tr&gt;
                                          &lt;/ItemTemplate&gt;
                                          &lt;EditItemTemplate&gt;
                                              &lt;tr&gt;
                                                  &lt;td&gt;&lt;asp:Label ID="lblID" runat="server" Text='&lt;%# Eval("BranchID") %&gt;' /&gt;&lt;/td&gt;
                                                  &lt;td&gt;&lt;asp:Label ID="lblBranchName" runat="server" Text='&lt;%# Eval("BranchName") %&gt;' /&gt;&lt;/td&gt;
                                                  &lt;td&gt;&lt;asp:TextBox ID="txtQty" runat="server" class="form-control input-sm" Text='&lt;%# Eval("Quantity") %&gt;' /&gt;&lt;/td&gt;
                                                  &lt;td&gt;&lt;asp:TextBox ID="txtCritical" runat="server" class="form-control input-sm" Text='&lt;%# Eval("CriticalLevel") %&gt;' /&gt;&lt;/td&gt;
                                                  &lt;td&gt;
                                                      &lt;asp:LinkButton ID="lnkUpdate" runat="server" class="glyphicon glyphicon-ok" CommandName="Update" /&gt;
                                                      &lt;asp:LinkButton ID="lnkCancel" runat="server" class="glyphicon glyphicon-remove" CommandName="Cancel" /&gt;
                                                  &lt;/td&gt;
                                              &lt;/tr&gt;
                                          &lt;/EditItemTemplate&gt;
                                      &lt;/asp:ListView&gt;
  
                                      &lt;/tbody&gt;
                                  &lt;/table&gt;    
                              &lt;/div&gt;
  
                          &lt;/div&gt;
                      &lt;/fieldset&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
  </code></pre>
  
  <p>.cs code</p>
  
  <pre><code>SqlConnection con = new SqlConnection(Helper.GetCon());
      DataTable ProdDetails;
  
      protected void Page_Load(object sender, EventArgs e)
      {
          if (!IsPostBack)
          {
              GetSuppliers();
              GetProdDetails();
  
          }
      }
  
      void GetSuppliers()
      {
          con.Open();
          SqlCommand cmd = new SqlCommand();
          cmd.Connection = con;
          cmd.CommandText = "SELECT SupplierID, SupplierName FROM Suppliers";
          SqlDataReader data = cmd.ExecuteReader();
          ddlSupplierName.DataSource = data;
          ddlSupplierName.DataTextField = "SupplierName";
          ddlSupplierName.DataValueField = "SupplierID";
          ddlSupplierName.DataBind();
          con.Close();
      }
  
      void GetProdDetails()
      {
          ProdDetails = (DataTable)Session["proddetails"];
  
          if (ProdDetails == null)
          {
              con.Open();
              SqlCommand cmd = new SqlCommand();
              cmd.Connection = con;
              cmd.CommandText = "SELECT b.BranchID, b.BranchName, pd.QtyonHand AS Quantity, " +
                  "pd.CriticalLevel FROM Branches AS b LEFT JOIN ProductDetails AS pd ON b.BranchID=pd.BranchID";
              SqlDataAdapter data = new SqlDataAdapter(cmd);
              ProdDetails = new DataTable();
              data.Fill(ProdDetails);
  
              DataRow[] rowList = ProdDetails.Select();
              foreach (DataRow dr in rowList)
              {
                  dr["Quantity"] = "0";
                  dr["CriticalLevel"] = "0";
              }
  
              lvWarehouse.DataSource = ProdDetails;
              lvWarehouse.DataBind();
              con.Close();
              Session["proddetails"] = ProdDetails;
          }
          else
          {
              lvWarehouse.DataSource = ProdDetails;
              lvWarehouse.DataBind();
              Session["proddetails"] = ProdDetails;
          }
          TotalQuantity();
      }
  
      void TotalQuantity()
      {
          int total = 0;
          for (int nRow = 0; nRow &lt;= ProdDetails.Rows.Count - 1; nRow++)
          {
              int qty = int.Parse(ProdDetails.Rows[nRow]["Quantity"].ToString());
              total = total + qty;
          }
          txtQuantity.Text = total.ToString(); ;
      }
  
  protected void lvWarehouse_ItemUpdating(object sender, ListViewUpdateEventArgs e)
      {
          GetProdDetails();
          string lblID = (lvWarehouse.Items[e.ItemIndex].FindControl("lblID") as Label).Text;
          TextBox Qty = (TextBox)lvWarehouse.Items[e.ItemIndex].FindControl("txtQty");
          string txtQty = (lvWarehouse.Items[e.ItemIndex].FindControl("txtQty") as TextBox).Text;
          string txtCritical = (lvWarehouse.Items[e.ItemIndex].FindControl("txtCritical") as TextBox).Text;
          foreach (DataRow row in ProdDetails.Rows)
          {
              if (row["BranchID"].ToString() == lblID)
              {
                  row["Quantity"] = Qty.Text;
                  row["CriticalLevel"] = txtCritical;
                  break;
              }
          }
          lvWarehouse.EditIndex = -1;
          GetProdDetails();
      }
  </code></pre>