title: Binding listView column dynamically in asp.net
body: <p>I need to create a listView in which the number of columns will be changing in runtime.</p>
  
  <p>My aspx page code:</p>
  
  <pre><code>&lt;asp:ListView runat="server" ID="ReportListView"&gt;
      &lt;LayoutTemplate&gt;
          &lt;table&gt;
              &lt;tr&gt;
                  &lt;asp:PlaceHolder runat="server" ID="itemPlaceHolder" /&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
      &lt;/LayoutTemplate&gt;
      &lt;ItemTemplate&gt;
          &lt;table&gt;
              &lt;tr&gt;
                  &lt;asp:PlaceHolder runat="server" ID="itemPlaceHolder1" /&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
      &lt;/ItemTemplate&gt;
  &lt;/asp:ListView&gt;
  </code></pre>
  
  <p>In ItemTemplate, I need to bind column dynamically from code behind.</p>
  
  <p>My .cs page code:</p>
  
  <pre><code>SqlCommand cmd = new SqlCommand(query);
  
      using (SqlConnection con = new SqlConnection(conString))
      {
          using (SqlDataAdapter sda = new SqlDataAdapter())
          {
              cmd.Connection = con;
              sda.SelectCommand = cmd;
              using (DataSet ds = new DataSet())
              {
                  sda.Fill(ds);
  
                  ReportListView.DataSource = ds;
                  ReportListView.DataBind();
              }
          }
      }
  
      foreach (ListViewDataItem listItem in ReportListView.Items)
      {
          PlaceHolder plc = (PlaceHolder)listItem.FindControl("itemPlaceHolder1");
          if (plc != null)
          {
                  Literal ltrl = new Literal();
                  ltrl.Text = "&lt;td&gt;" + listItem.DataItem + "&lt;/td&gt;";
                  plc.Controls.Add(ltrl);
  
          }
      }
  </code></pre>
  
  <p>But it return nothing on the browser. no error and no output....</p>
  
  <p>Any Suggestions...... </p>