title: how to add link button using datatable as datasource to gridview dynamically?
body: <p>Here i did every thing from codebehind.I created a gridview dynamically.</p>
  
  <p>DataTable dt=null;<br>
   dt = loadDynamicGrid(columnname, ds);</p>
  
  <p>GridView grdnew = new GridView();</p>
  
  <p>grdnew.DataSource = dt;</p>
  
  <p>grdnew.DataBind();</p>
  
  <pre><code>private DataTable loadDynamicGrid(string [] column,DataSet ds)
  {       
      #region Code for preparing the DataTable
  
      DataTable dt = new DataTable();
  
      //Create an ID column for adding to the Datatable
      DataColumn dcol ;//= new DataColumn(ID1, typeof(System.Int32));
      ButtonColumn btncolm;
      HyperLinkColumn hplink;
  
      for (int i = 0; i &lt; column.Count(); i++)
      {
          if (column[i] != "" &amp; column[i]!=null)
          {
              if (column[i] == "BUY" || column[i] == "Buy" || column[i] == "BuyNow" || column[i] == "Details" || column[i] == "ViewDetails" || column[i] == "BuyQty" || column[i] == "Purchase")
              {
                  //btncolm = new ButtonColumn();
                  //btncolm.HeaderText = column[i];
                  //btncolm.Text = column[i];
  
                  //dt.Columns.Add(btncolm.Text);
                  hplink = new HyperLinkColumn();
  
                  hplink.HeaderImageUrl = "http://www.google.com";
                  hplink.HeaderText = column[i];
                  hplink.Text = column[i];
                  dt.Columns.Add(hplink.Text);
  
              }
              else
              {
                  dcol = new DataColumn(column[i], typeof(System.String));
                  dt.Columns.Add(dcol);
              }
          }
      }
  
      int k=0;
  
      foreach (DataRow dr in ds.Tables[0].Rows)
      {
          DataRow myrow = dt.NewRow();
          for (int j = 0; j &lt; column.Count(); j++)
          {
              if (column[j] != "" &amp; column[j] != null)
              {
  
                  string sdfsd = Convert.ToString(dr[column[j]]);
                  if (column[j] == "BUY" || column[j] == "Buy" || column[j] == "BuyNow" || column[j] == "Details" || column[j] == "ViewDetails" || column[j] == "BuyQty" || column[j] == "Purchase")
                  {
                     //myrow[column[j]] = "http://www.google.com1/";
                     myrow[column[j]] = dr[column[j]];
                  }                    
                  else
                  {
                      if (Convert.ToString(dr[column[j]]).TrimEnd() == "&amp;nbsp;")
                      {
                          myrow[column[j]] = "";
                      }
                      else
                      {
                          myrow[column[j]] = dr[column[j]];
                      }
                  }
                  if (column[j] == "Stock" || column[j] == "QtyInStock" || column[j] == "Qty" || column[j] == "Available" || column[j].ToLower() == "onhand" || column[j] == "QuantityOnHand" || column[j] == "QtyAvailable" || column[j] == "InStock" || column[j] == "Avail" || column[j] == "Inventory" || column[j] == "Quantity" || column[j] == "Availability")
                  {
                      if (Convert.ToString(dr[column[j]]) != "0" &amp;&amp; Convert.ToString(dr[column[j]]) != "" &amp;&amp; dr[column[j]] != null &amp;&amp; Convert.ToString(dr[column[j]]).TrimEnd()!="&amp;nbsp;")
                      {
                          stock = dr[column[j]].ToString();
                      }
                  }
  
              }
          }
          k++;
          dt.Rows.Add(myrow);          
  
      }       
  
      #endregion
  
      column = null;
  
      return dt;      
  }
  </code></pre>
  
  <p>Then i adding to a div everytime like: </p>
  
  <p>mydiv.Controls.Add(grdnew);</p>
  
  <p>as above i repeate the loop for different table of data to bind to gridview.Here i need a link button to gridview.so i added a hyperlink column to datatable,but i'm not getting any linkbutton in grid.I have more than 20 tables of data to bind to grid.so i preferred to create the grid dynamically.</p>