title: Error Specified argument was out of the range of valid values. Parameter name: index in DataGridview Row Data Bound
body: <p>I got an error of</p>
  
  <blockquote>
    <p>Description: An unhandled exception occurred during the execution of
    the current web request. Please review the stack trace for more
    information about the error and where it originated in the code.</p>
    
    <p>Exception Details: System.ArgumentOutOfRangeException: Specified
    argument was out of the range of valid values. Parameter name: index</p>
  </blockquote>
  
  <p>Source Error: </p>
  
  <pre><code>if (e.Row.RowType == DataControlRowType.DataRow)
  {
      LinkButton _singleClickButton = (LinkButton)e.Row.Cells[0].Controls[2];
      string _jsSingle = ClientScript.GetPostBackClientHyperlink(_singleClickButton, "Select$" + e.Row.RowIndex);
      e.Row.Style["cursor"] = "hand";
  </code></pre>
  
  <p>my code</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
      if (!this.IsPostBack)
      {
          DataTable dt = new DataTable();
          dt.Columns.AddRange(new DataColumn[3] { new DataColumn("itemid", typeof(string)),
                  new DataColumn("itemdesc", typeof(string)),
                  new DataColumn("itemtype",typeof(string)) });
          dt.Rows.Add("FG001", "Red Velvet Cake (8'' round)","Dry Goods");
          dt.Rows.Add("FG002", "Voilet Velvet Cake (8'' round)", "Dry Goods");
          GridView1.DataSource = dt;
          GridView1.DataBind();  
      }
  }
  
  protected void OnDataBound(object sender, EventArgs e)
  {
      GridViewRow row = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal);
      for (int i = 0; i &lt; GridView1.Columns.Count; i++)
      {
          TableHeaderCell cell = new TableHeaderCell();
          TextBox txtSearch = new TextBox();
          txtSearch.Attributes["placeholder"] = GridView1.Columns[i].HeaderText;
          txtSearch.CssClass = "search_textbox";
  
          cell.Controls.Add(txtSearch);
          row.Controls.Add(cell);
      }
  
      GridView1.HeaderRow.Parent.Controls.AddAt(1, row);
  }
  
  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  {
      if (!IsPostBack)
      {
          if (e.Row.RowType == DataControlRowType.DataRow)
          {
              LinkButton _singleClickButton = (LinkButton)e.Row.Cells[0].Controls[0];
              string _jsSingle = ClientScript.GetPostBackClientHyperlink(_singleClickButton, "Select$" + e.Row.RowIndex);
              e.Row.Style["cursor"] = "hand";
              e.Row.Attributes["onclick"] = _jsSingle;
          } 
      }
  }
  
  protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
  {
      GridViewRow selectedRow = GridView1.SelectedRow;
      hiddenitemid.Value = selectedRow.Cells[0].Text;
  }
  </code></pre>
  
  <p>the error pointing</p>
  
  <pre><code>LinkButton _singleClickButton = (LinkButton)e.Row.Cells[0].Controls[0];
  </code></pre>