title: Textboxes Causing Problems in ASP.NET C# SQL
body: <p>I am using a nested Gridview(I have 5 Nested Gridviews).
  I have applied a Regular Field validator for these Gridviews.</p>
  
  <p>But once I click the button, commas are generated in the textbox. Due to that whenever I click the button, all the validation get fired.</p>
  
  <p>I have researched lots of articles but have not found one related to this.</p>
  
  <p>Here is the image for the Gridview with the commas generated in the textbox:</p>
  
  <p><img src="https://i.stack.imgur.com/M3WZj.png" alt="Image Of Error Page"></p>
  
  <p><strong>HTML Code Part</strong></p>
  
  <pre><code>&lt;%-- First Gridview--%&gt;
  &lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"
      CssClass="gvstyling gridview_width_60" ShowHeaderWhenEmpty="true" EmptyDataText="Record(s) Not Found!"
      DataKeyNames="locality" ShowHeader="false" OnRowDataBound="gvLocality_RowDataBound"&gt;
      &lt;Columns&gt;
  
          &lt;asp:TemplateField ItemStyle-Width="15px"&gt;
              &lt;ItemTemplate&gt;
                  &lt;img alt="" style="cursor: pointer" src="../images/plus.png" /&gt;
  
                  &lt;asp:Panel ID="pnlCompanyName" runat="server" Style="display: none"&gt;
  
                      &lt;%-- Second Gridview --%&gt;
                      &lt;asp:GridView ID="gvCompanyName" ShowHeader="false" ShowHeaderWhenEmpty="false" CssClass="gvstyling gridview_width_100"
                          OnRowDataBound="gvCompanyName_RowDataBound" runat="server"
                          AutoGenerateColumns="false" EmptyDataText="No Record(s) Found!"&gt;
  
                          &lt;Columns&gt;
  
                              &lt;asp:TemplateField ItemStyle-Width="15px"&gt;
                                  &lt;ItemTemplate&gt;
                                      &lt;asp:HiddenField ID="hfRetailer_Id" Value='&lt;%# Eval("retailer_id") %&gt;' runat="server"&gt;&lt;/asp:HiddenField&gt;
                                      &lt;asp:HiddenField ID="hfLocality" Value='&lt;%# Eval("locality") %&gt;' runat="server"&gt;&lt;/asp:HiddenField&gt;
                                      &lt;asp:Label ID="lbl" Visible="false" Text='&lt;%# Eval("retailer_id") %&gt;' runat="server"&gt;&lt;/asp:Label&gt;
                                      &lt;img alt="" style="cursor: pointer" src="../images/plus.png" /&gt;
  
                                      &lt;asp:Panel ID="pnlSellOrderNo" runat="server" Style="display: none"&gt;
  
                                          &lt;%-- Third Gridview --%&gt;
                                          &lt;asp:GridView ID="gvSellOrderNo" ShowHeader="false" ShowHeaderWhenEmpty="false"
                                              CssClass="gvstyling gridview_width_100" runat="server" OnRowDataBound="gvSellOrderNo_RowDataBound"
                                              AutoGenerateColumns="false" EmptyDataText="No Record(s) Found!"&gt;
                                              &lt;Columns&gt;
                                                  &lt;asp:TemplateField ItemStyle-Width="15px"&gt;
                                                      &lt;ItemTemplate&gt;
                                                          &lt;asp:HiddenField ID="hf_SellOrderNo" Value='&lt;%# Eval("sell_order_no") %&gt;' runat="server"&gt;&lt;/asp:HiddenField&gt;
                                                          &lt;asp:Label ID="lblSellOrderNo" Visible="false" Text='&lt;%# Eval("sell_order_no") %&gt;' runat="server"&gt;&lt;/asp:Label&gt;
                                                          &lt;img alt="" style="cursor: pointer" src="../images/plus.png" /&gt;
                                                          &lt;asp:Panel ID="pnlProductDetails" runat="server" Style="display: none"&gt;
  
                                                              &lt;%-- fourth Gridview --%&gt;
                                                              &lt;asp:GridView ID="gvProductDetails" ShowHeader="false" ShowHeaderWhenEmpty="false"
                                                                  CssClass="gvstyling gridview_width_100" runat="server" OnRowDataBound="gvProductDetails_RowDataBound"
                                                                  AutoGenerateColumns="false" EmptyDataText="No Record(s) Found!"&gt;
                                                                  &lt;Columns&gt;
  
                                                                      &lt;asp:TemplateField ItemStyle-Width="15px"&gt;
                                                                          &lt;ItemTemplate&gt;
                                                                              &lt;asp:HiddenField ID="HiddenField1" Value='&lt;%# Eval("sell_order_no") %&gt;' runat="server"&gt;&lt;/asp:HiddenField&gt;
                                                                              &lt;asp:HiddenField ID="hfProductId" Value='&lt;%# Eval("product_id") %&gt;' runat="server"&gt;&lt;/asp:HiddenField&gt;
                                                                              &lt;asp:Label ID="lblProductId" Visible="false" Text='&lt;%# Eval("product_id") %&gt;' runat="server"&gt;&lt;/asp:Label&gt;
  
                                                                              &lt;img alt="" style="cursor: pointer" src="../images/plus.png" /&gt;
                                                                              &lt;asp:Panel ID="pnlWarehouseDetails" runat="server" Style="display: none"&gt;
  
                                                                                  &lt;%-- fifth Gridview--%&gt;
                                                                                  &lt;asp:GridView ID="gvWarehouseDetails" ShowHeader="false" ShowHeaderWhenEmpty="false"
                                                                                      CssClass="gvstyling gridview_width_100" runat="server"
                                                                                      AutoGenerateColumns="false"&gt;
  
                                                                                      &lt;Columns&gt;
                                                                                          &lt;asp:TemplateField&gt;
                                                                                              &lt;ItemTemplate&gt;
                                                                                                  &lt;asp:Label ID="lblWarehouseId" Text='&lt;%# Eval("c_warehouse_id") %&gt;' Visible="false" runat="server"&gt;&lt;/asp:Label&gt;
                                                                                                  &lt;%# Eval("warehouse_name") %&gt; (&lt;%# Eval("qty") %&gt;)
                                                                                              &lt;/ItemTemplate&gt;
                                                                                          &lt;/asp:TemplateField&gt;
  
                                                                                          &lt;asp:TemplateField&gt;
                                                                                              &lt;ItemTemplate&gt;
                                                                                                  &lt;asp:TextBox ID="txtQty" runat="server"&gt;&lt;/asp:TextBox&gt;
                                                                                              &lt;/ItemTemplate&gt;
                                                                                          &lt;/asp:TemplateField&gt;
                                                                                      &lt;/Columns&gt;
  
                                                                                  &lt;/asp:GridView&gt;
  
                                                                                  &lt;%-- fifth Gridview --%&gt;
                                                                              &lt;/asp:Panel&gt;
                                                                          &lt;/ItemTemplate&gt;
                                                                      &lt;/asp:TemplateField&gt;
  
  
  
                                                                      &lt;asp:TemplateField&gt;
                                                                          &lt;ItemTemplate&gt;
                                                                              &lt;%# Eval("product_name") %&gt; (&lt;%# Eval("qty") %&gt;)
                                                                          &lt;/ItemTemplate&gt;
                                                                      &lt;/asp:TemplateField&gt;
                                                                  &lt;/Columns&gt;
                                                              &lt;/asp:GridView&gt;
                                                              &lt;%-- fourth Gridview --%&gt;
                                                          &lt;/asp:Panel&gt;
                                                      &lt;/ItemTemplate&gt;
                                                  &lt;/asp:TemplateField&gt;
  
                                                  &lt;asp:TemplateField&gt;
                                                      &lt;ItemTemplate&gt;
                                                          &lt;%# Eval("sell_order_no") %&gt;
                                                      &lt;/ItemTemplate&gt;
                                                  &lt;/asp:TemplateField&gt;
                                              &lt;/Columns&gt;
                                          &lt;/asp:GridView&gt;
                                          &lt;%-- Third Gridview --%&gt;
                                      &lt;/asp:Panel&gt;
                                  &lt;/ItemTemplate&gt;
                              &lt;/asp:TemplateField&gt;
  
                              &lt;asp:TemplateField HeaderText="Business Name"&gt;
                                  &lt;ItemTemplate&gt;
                                      &lt;%# Eval("business_name") %&gt;
                                  &lt;/ItemTemplate&gt;
                              &lt;/asp:TemplateField&gt;
  
                          &lt;/Columns&gt;
  
                      &lt;/asp:GridView&gt;
                      &lt;%-- Second  Gridview--%&gt;
                  &lt;/asp:Panel&gt;
              &lt;/ItemTemplate&gt;
          &lt;/asp:TemplateField&gt;
  
          &lt;asp:TemplateField ItemStyle-CssClass="gv_item_bg"&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:Label ID="lblLocality" runat="server" Text=' &lt;%# Eval("locality") %&gt;'&gt;&lt;/asp:Label&gt;
              &lt;/ItemTemplate&gt;
          &lt;/asp:TemplateField&gt;
  
      &lt;/Columns&gt;
  &lt;/asp:GridView&gt;
  &lt;%-- First Gridview --%&gt;
  </code></pre>
  
  <p><strong>Code Behind File</strong></p>
  
  <pre><code>//Filling Shipping Company Name
  private void FillShippingCompanyName()
  {
      try
      {
          ArrayList arr = new ArrayList();
          cm.ds.Clear();
          cm.sp_dataset_execute("spdisplay_Shipping_Comany_Name", arr);
  
          ddlCompanyName.DataSource = cm.ds;
          ddlCompanyName.DataValueField = "shipping_code";
          ddlCompanyName.DataTextField = "shipping_name";
          ddlCompanyName.DataBind();
          ddlCompanyName.Items.Insert(0, new ListItem("---- Select Shipping Company ----", "0"));
      }
      catch (Exception ex)
      {
          ErrHandler.WriteError(ex.Message.ToString(), "Shipping-Order-FillShippingCompanyName()");
      }
      finally
      {
          cm.con.Close();
      }
  
  }
  
  private void FillLocality()
  {
      try
      {
          cm.ds.Clear();
          ArrayList arr = new ArrayList();
          cm.sp_dataset_execute("spDisplay_Locality", arr);
  
          gvLocality.DataSource = cm.ds;
          gvLocality.DataBind();
      }
      catch (Exception ex)
      {
          ErrHandler.WriteError(ex.Message.ToString(), "Shipping-Order-FillLocality()");
          cm.con.Close();
      }
      finally
      {
          cm.con.Close();
      }
  }
  
  //Locality Gridview Row Databound (Level 1 Grdview)
  common cm1 = new common();
  protected void gvLocality_RowDataBound(object sender, GridViewRowEventArgs e)
  {
      try
      {
          if (e.Row.RowType == DataControlRowType.DataRow)
          {
              string Locality = gvLocality.DataKeys[e.Row.RowIndex].Value.ToString();
              GridView gvCompanyName = e.Row.FindControl("gvCompanyName") as GridView;
  
              cm1.ds.Clear();
              //Binding Company Gridview
              ArrayList arr1 = new ArrayList();
              arr1.Add("@locality|" + Locality + "");
              cm1.sp_dataset_execute("spDisplayCompanyName", arr1);
  
              gvCompanyName.DataSource = cm1.ds;
              gvCompanyName.DataBind();
          }
      }
      catch (Exception ex)
      {
          ErrHandler.WriteError(ex.Message.ToString(), "Recent_activity-gvRecentActivityOuter_RowDataBound()");
          cm1.con.Close();
      }
      finally
      {
          cm1.con.Close();
      }
  }
  
  //Comapny Name Gridview Row Databound (Level 2 Grdview)
  common cm2 = new common();
  protected void gvCompanyName_RowDataBound(object sender, GridViewRowEventArgs e)
  {
      try
      {
          if (e.Row.RowType == DataControlRowType.DataRow)
          {
              string RetailerId = ((HiddenField)e.Row.FindControl("hfRetailer_Id")).Value;
              GridView gvSellOrderNo = e.Row.FindControl("gvSellOrderNo") as GridView;
              string Locality = ((HiddenField)e.Row.FindControl("hfLocality")).Value;
  
  
  
              cm2.ds.Clear();
              //Binding Company Gridview
              ArrayList arr = new ArrayList();
              arr.Add("@retailer_id|" + RetailerId + "");
              arr.Add("@locality|" + Locality + "");
              cm2.sp_dataset_execute("spDisplay_SellOrderNo", arr);
  
              gvSellOrderNo.DataSource = cm2.ds;
              gvSellOrderNo.DataBind();
          }
      }
      catch (Exception ex)
      {
          ErrHandler.WriteError(ex.Message.ToString(), "Shipping-Order-Page_Load()");
          cm2.con.Close();
      }
      finally
      {
          cm2.con.Close();
      }
  }
  
  //Sell Order Gridview Row Databound (Level 3 Grdview)
  common cm3 = new common();
  protected void gvSellOrderNo_RowDataBound(object sender, GridViewRowEventArgs e)
  {
      try
      {
          if (e.Row.RowType == DataControlRowType.DataRow)
          {
              string SellOrderNo = ((HiddenField)e.Row.FindControl("hf_SellOrderNo")).Value;
              GridView gvProductDetails = e.Row.FindControl("gvProductDetails") as GridView;
  
              FillProductDetails(gvProductDetails, SellOrderNo);
          }
      }
      catch (Exception ex)
      {
          ErrHandler.WriteError(ex.Message.ToString(), "Shipping-Order-gvSellOrderNo_RowDataBound()");
          cm3.con.Close();
      }
      finally
      {
          cm3.con.Close();
      }
  }
  
  private void FillProductDetails(GridView gvProductDetails, string SellOrderNo)
  {
  
      cm3.ds.Clear();
      //Product Details Gridview
      ArrayList arr = new ArrayList();
      arr.Add("@sell_order_no|" + SellOrderNo + "");
  
      cm3.sp_dataset_execute("spDisplay_ProductDetails", arr);
  
      gvProductDetails.DataSource = cm3.ds;
      gvProductDetails.DataBind();
  }
  
  //Product Details Gridview Row Databound (Level 4 Grdview)
  common cm4 = new common();
  protected void gvProductDetails_RowDataBound(object sender, GridViewRowEventArgs e)
  {
      try
      {
          if (e.Row.RowType == DataControlRowType.DataRow)
          {
              string ProductID = ((HiddenField)e.Row.FindControl("hfProductId")).Value;
  
              string SellOrderNo = ((HiddenField)e.Row.FindControl("HiddenField1")).Value;
  
              GridView gvWarehouseDetails = e.Row.FindControl("gvWarehouseDetails") as GridView;
  
              cm4.ds.Clear();
              //Product Details Gridview
              ArrayList arr = new ArrayList();
              arr.Add("@product_id|" + ProductID + "");
              arr.Add("@sell_order_no|" + SellOrderNo + "");
  
              cm4.sp_dataset_execute("spDisplay_WarehouseDetails", arr);
  
              gvWarehouseDetails.DataSource = cm4.ds;
              gvWarehouseDetails.DataBind();
          }
      }
      catch (Exception ex)
      {
          ErrHandler.WriteError(ex.Message.ToString(), "Shipping-Order-gvProductDetails_RowDataBound()");
          cm4.con.Close();
      }
      finally
      {
          cm4.con.Close();
      }
  }
  
  //Submit Button
  protected void btnSubmit_Click1(object sender, EventArgs e)
  {
      try
      {
          cm.ds.Clear();
          //--Insert Query for Rs_Shipping_Order_Details
          string ShippingCode = "SHO" + DateTime.Now.ToString("yyyyMMddHHmmss");
  
          string ShippingGroup = "SG" + DateTime.Now.ToString("yyyyMMddHHmmss");
  
          ArrayList arr = new ArrayList();
          arr.Add("@shipping_code|" + ShippingCode + "");
          arr.Add("@shipping_Company_code|" + ddlCompanyName.SelectedValue + "");
          arr.Add("@is_shipping_delivered|0");
          cm.sp_execute("spInsert_Shipping_Order_Detail", arr);
  
          //Locality for loop
          for (int i = 0; i &lt; gvLocality.Rows.Count; i++)
          {
              GridView gvCompanyName = gvLocality.Rows[i].FindControl("gvCompanyName") as GridView;
  
              //Company for loop
              for (int j = 0; j &lt; gvCompanyName.Rows.Count; j++)
              {
                  GridView gvSellOrderNo = gvCompanyName.Rows[j].FindControl("gvSellOrderNo") as GridView;
  
                  string RetailerId = ((Label)gvCompanyName.Rows[j].FindControl("lbl")).Text;
  
  
                  //Sell Order for loop
                  for (int k = 0; k &lt; gvSellOrderNo.Rows.Count; k++)
                  {
                      //Product Details Gridview
                      GridView gvProductDetails = gvSellOrderNo.Rows[k].FindControl("gvProductDetails") as GridView;
                      string SO = ((Label)gvSellOrderNo.Rows[k].FindControl("lblSellOrderNo")).Text;
                      int retailer_Id = Convert.ToInt32(RetailerId);
  
                      //Product Details for loop
                      for (int l = 0; l &lt; gvProductDetails.Rows.Count; l++)
                      {
  
                          //Warehouse Details Gridview
                          GridView gvWarehouseDetails = gvProductDetails.Rows[l].FindControl("gvWarehouseDetails") as GridView;
  
                          string ProductId = ((Label)gvProductDetails.Rows[l].FindControl("lblProductId")).Text;
  
                          //Warehouse Details for loop
                          for (int m = 0; m &lt; gvWarehouseDetails.Rows.Count; m++)
                          {
                              TextBox txtQty = gvWarehouseDetails.Rows[m].FindControl("txtQty") as TextBox;
                              string LastValue = txtQty.Text.Split(',').Last();
  
                              if (String.IsNullOrEmpty(LastValue) == false)
                              {
                                  string Warehouse_Id = ((Label)gvWarehouseDetails.Rows[m].FindControl("lblWarehouseId")).Text;
                                  int warehouse_id = Convert.ToInt32(Warehouse_Id);
                                  string Qty = LastValue;
  
                                  //Insert Query for Rs_Shipping_Detail_Mapping
                                  ArrayList arr1 = new ArrayList();
                                  arr1.Add("@shipping_order_code|" + ShippingCode + "");
                                  arr1.Add("@retailer_id|" + retailer_Id + "");
                                  arr1.Add("@sell_order_no|" + SO + "");
                                  arr1.Add("@product_id|" + ProductId + "");
                                  arr1.Add("@c_warehouse_id|" + warehouse_id + "");
                                  arr1.Add("@shipping_group|" + ShippingGroup + "");
                                  arr1.Add("@qty|" + Qty + "");
  
                                  common cm1 = new common();
                                  cm1.sp_execute("spInsert_Shipping_Detail_Mapping", arr1);
  
  
                                  ////Generating Pdf for Each Sell Order
                                  //if (m == gvWarehouseDetails.Rows.Count - 1)
                                  //{
                                  //    Generate_SellOrderWise_PDf(SO, ShippingCode, ShippingGroup);
                                  //}
                              }
                          }
                      }
                  }
              }
          }
          Response.Redirect("../final-shipping-order/?SG=" + ShippingGroup, false);
      }
      catch (Exception ex)
      {
          ErrHandler.WriteError(ex.Message.ToString(), "Shipping-Order-btnSubmit_Click1()");
          cm4.con.Close();
      }
      finally
      {
          cm4.con.Close();
      }
  }    
  </code></pre>
  
  <p><strong>Question :</strong></p>
  
  <p><strong>1. How do I remove the commas from the textboxes?</strong></p>
  
  <p><strong>2. Reason for these commas? (Why are the commas being generated on the button click?)</strong></p>
  
  <p><strong>3. Limit for the Nested Gridview ?</strong></p>
  
  <p>Any help will be appreciated.</p>