title: Add rows to gridview using jquery
body: <p>initially my gridview is bind with one data and when user click on add more button then i add one row at a time to gridview by jquery. my code is working fine but the problem is when i added 5 rows to gridview from client side by jquery and when i try to iterate in those rows from server side then <code>GridView1.Rows.Count</code> always return one row. so my problem is i am not being able to iterate in rows collection from server side when rows are added from client side by jquery. so here i am giving my whole code and just tell me what i can do as a result i will be able to read all rows from server side after adding those rows by jquery.</p>
  
  <h2>ASPX</h2>
  
  <pre><code>&lt;script&gt;
       $(document).ready(function () {
          $("#datepicker").datepicker({ 
              dateFormat: 'dd/mm/yy',
              showOn: "both",
              buttonImageOnly: true,
              buttonImage: "images/date_picker.gif",
              buttonText: "Calendar"
           });
  
  
          $('#&lt;%=btnAdd.ClientID %&gt;').bind('click', function (event) {
              var $grid = $('#&lt;%=GridView1.ClientID %&gt;');
              var $row = $grid.find('tr:last').clone().appendTo($grid);
              $row.find('select')[0].selectedIndex = 0;
              return false;
          });
      });
  &lt;/script&gt;
  
  &lt;asp:Button ID="btnAdd" Text="Add More" runat="server" /&gt;&lt;br /&gt;
  &lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" ShowHeader="False"&gt;
         &lt;Columns&gt;
             &lt;asp:TemplateField&gt;
                 &lt;ItemTemplate&gt;
                     &lt;asp:DropDownList ID="ddlCountry" runat="server"&gt;
                      &lt;asp:ListItem&gt;--Select--&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;India&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;UK&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;USA&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;Germany&lt;/asp:ListItem&gt;
                  &lt;/asp:DropDownList&gt;
  
  
  
      &lt;asp:DropDownList ID="ddlCity" runat="server"&gt;
                      &lt;asp:ListItem&gt;--Select--&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;Kolkata&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;Mumbai&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;Delhi&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;Madras&lt;/asp:ListItem&gt;
                  &lt;/asp:DropDownList&gt;
                 &lt;/ItemTemplate&gt;
             &lt;/asp:TemplateField&gt;
         &lt;/Columns&gt;
     &lt;/asp:GridView&gt;
  &lt;br /&gt;&lt;br /&gt;
  &lt;asp:Button ID="Button1" Text="Read gridview Value" runat="server" 
      onclick="Button1_Click" /&gt;&lt;br /&gt;
  </code></pre>
  
  <h2>ServerSide Code</h2>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
          {
              if (!IsPostBack)
              {
                  DataTable dt = new DataTable();
                  dt.Columns.Add("ID", typeof(string));
                  DataRow dr = dt.NewRow();
                  dr["ID"] = "";
                  dt.Rows.Add(dr);
                  GridView1.DataSource = dt;
                  GridView1.DataBind();
              }
          }
  
          protected void Button1_Click(object sender, EventArgs e)
          {
              StringBuilder sb=new StringBuilder();
  
              //HtmlTable table = (HtmlTable)rpt.Items[0].FindControl("tblSample");
  
              for (int i = 0; i &lt;= GridView1.Rows.Count - 1; i++)
              {
                  string country = ((DropDownList)GridView1.Rows[i].FindControl("ddlCountry")).SelectedItem.Text;
                  string city = ((DropDownList)GridView1.Rows[i].FindControl("ddlCity")).SelectedItem.Text;
                  sb.Append("Country :- " + country + "  City :- " + city);
              }
              txtData.Text = sb.ToString();
          }
  </code></pre>