title: Link button to display grid view asp.net dynamically
body: <p>I have to display <code>n</code> grids, <code>n</code> is variable, then I dont know how many grids I'll have.</p>
  
  <p>My problem is, I have to init this grids with Visible false and when click in a button show the grid specific for that button, then how can I link a button to a gridview?</p>
  
  <p>My code that generate the grids:</p>
  
  <pre><code>    foreach (List&lt;DataRow&gt; lst in grids)
      {
  
          dt = lst.CopyToDataTable();
  
          GridView grv = new GridView();
          grv.AlternatingRowStyle.BackColor = System.Drawing.Color.FromName("#cccccc");
          grv.HeaderStyle.BackColor = System.Drawing.Color.Gray;
          grv.ID = "grid_view"+i;
          grv.Visible = false;
          grv.DataSource = dt;
          grv.DataBind();
  
  
          Label lblBlankLines = new Label();
          lblBlankLines.Text = "&lt;br /&gt;&lt;br /&gt;";
  
  
          Label lblTipo = new Label();
          string tipoOcorrencia = lst[0]["DESC_OCORRENCIA"].ToString();
          tipoOcorrencia = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(tipoOcorrencia);
          int quantidade = lst.Count;
          lblTipo.Text = tipoOcorrencia + ": " + quantidade;
  
  
          LinkButton lkBtn = new LinkButton();
          lkBtn.ID = "link_button"+i;
          lkBtn.Text = "+";
  
          place_grids.Controls.Add(lblBlankLines);
          place_grids.Controls.Add(lkBtn);
          place_grids.Controls.Add(lblTipo);
          place_grids.Controls.Add(grv);
  
  
          place_grids.DataBind();
  
          i++;
      }
  </code></pre>
  
  <p>Thanks in advance.</p>