title: Add new rows to gridview in asp.net
body: <p>As i add new rows, i want the default values for the new rows to be zero. The new rows are added now when i click the addNewRows button but they are just blank.  How can i preassign to zero value for each of the column in the row?</p>
  
  <pre><code> private void AddNewRow()
      {
        int rowIndex = 0;
  
        if (ViewState["CurrentTable"] != null)
        {
          DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"];
          DataRow drCurrentRow = null;
          if (dtCurrentTable.Rows.Count &gt; 0)
          {
            for (int i = 1; i &lt;= dtCurrentTable.Rows.Count; i++)
            {
              DropDownList ddlTaskCurrWeek = (DropDownList)myGridView.Rows[rowIndex].Cells[1].FindControl("ddlTaskCurrWeek");
              TextBox TextBoxDay1 = (TextBox)myGridView.Rows[rowIndex].Cells[2].FindControl("txtDay1");
              TextBox TextBoxDay2 = (TextBox)myGridView.Rows[rowIndex].Cells[3].FindControl("txtDay2");
              TextBox TextBoxDay3 = (TextBox)myGridView.Rows[rowIndex].Cells[4].FindControl("txtDay3");
              TextBox TextBoxDay4 = (TextBox)myGridView.Rows[rowIndex].Cells[5].FindControl("txtDay4");
              TextBox TextBoxDay5 = (TextBox)myGridView.Rows[rowIndex].Cells[6].FindControl("txtDay5");
              TextBox TextBoxDay6 = (TextBox)myGridView.Rows[rowIndex].Cells[7].FindControl("txtDay6");
              TextBox TextBoxDay7 = (TextBox)myGridView.Rows[rowIndex].Cells[8].FindControl("txtDay7");
              Label lbl8 = (Label)myGridView.Rows[rowIndex].Cells[9].FindControl("lblTotal");
              // TextBox TextBoxDay8 = (TextBox)myGridView.Rows[rowIndex].Cells[9].FindControl("txtDay8");
  
  
              drCurrentRow = dtCurrentTable.NewRow();
              drCurrentRow["RowNumber"] = i + 1;
              dtCurrentTable.Rows[i - 1]["Col1"] = ddlTaskCurrWeek.SelectedValue;
              dtCurrentTable.Rows[i - 1]["Col2"] = TextBoxDay1.Text;
              dtCurrentTable.Rows[i - 1]["Col3"] = TextBoxDay2.Text;
              dtCurrentTable.Rows[i - 1]["Col4"] = TextBoxDay3.Text;
              dtCurrentTable.Rows[i - 1]["Col5"] = TextBoxDay4.Text;
              dtCurrentTable.Rows[i - 1]["Col6"] = TextBoxDay5.Text;
              dtCurrentTable.Rows[i - 1]["Col7"] = TextBoxDay6.Text;
              dtCurrentTable.Rows[i - 1]["Col8"] = TextBoxDay7.Text;
              dtCurrentTable.Rows[i - 1]["Col9"] = lbl8.Text;
              //  dtCurrentTable.Rows[i - 1]["Col9"] = TextBoxDay8.Text;
  
  
  
              rowIndex++;
            }
            dtCurrentTable.Rows.Add(drCurrentRow);
            ViewState["CurrentTable"] = dtCurrentTable;
  
            myGridView.DataSource = dtCurrentTable;
            myGridView.DataBind();         
          }
        }
        else
        {
          Response.Write("ViewState is null");
        }
        SetPreviousData();
      }
  </code></pre>
  
  <p>here is setPreviousData code</p>
  
  <pre><code>private void SetPreviousData()
      {
        int rowIndex = 0;
        if (ViewState["CurrentTable"] != null)
        {
          DataTable dt = (DataTable)ViewState["CurrentTable"];
          if (dt.Rows.Count &gt; 0)
          {
            for (int i = 0; i &lt; dt.Rows.Count; i++)
            {
              DropDownList ddlTaskCurrWeek = (DropDownList)myGridView.Rows[rowIndex].Cells[1].FindControl("ddlTaskCurrWeek");
              TextBox TextBoxDay1 = (TextBox)myGridView.Rows[rowIndex].Cells[2].FindControl("txtDay1");
              TextBox TextBoxDay2 = (TextBox)myGridView.Rows[rowIndex].Cells[3].FindControl("txtDay2");
              TextBox TextBoxDay3 = (TextBox)myGridView.Rows[rowIndex].Cells[4].FindControl("txtDay3");
              TextBox TextBoxDay4 = (TextBox)myGridView.Rows[rowIndex].Cells[5].FindControl("txtDay4");
              TextBox TextBoxDay5 = (TextBox)myGridView.Rows[rowIndex].Cells[6].FindControl("txtDay5");
              TextBox TextBoxDay6 = (TextBox)myGridView.Rows[rowIndex].Cells[7].FindControl("txtDay6");
              TextBox TextBoxDay7 = (TextBox)myGridView.Rows[rowIndex].Cells[8].FindControl("txtDay7");
              Label lbl8 = (Label)myGridView.Rows[rowIndex].Cells[9].FindControl("lblTotal");
              // TextBox TextBoxDay8 = (TextBox)myGridView.Rows[rowIndex].Cells[9].FindControl("txtDay8");
  
              // drCurrentRow["RowNumber"] = i + 1;
  
              myGridView.Rows[i].Cells[0].Text = Convert.ToString(i + 1);
              ddlTaskCurrWeek.SelectedValue = dt.Rows[i]["Col1"].ToString();
              TextBoxDay1.Text = dt.Rows[i]["Col2"].ToString();
              TextBoxDay2.Text = dt.Rows[i]["Col3"].ToString();
              TextBoxDay3.Text = dt.Rows[i]["Col4"].ToString();
              TextBoxDay4.Text = dt.Rows[i]["Col5"].ToString();
              TextBoxDay5.Text = dt.Rows[i]["Col6"].ToString();
              TextBoxDay6.Text = dt.Rows[i]["Col7"].ToString();
              TextBoxDay7.Text = dt.Rows[i]["Col8"].ToString();
              lbl8.Text = dt.Rows[i]["Col9"].ToString();
  
              rowIndex++;
            }
          }
        }
      }
  </code></pre>