title: iTextSharp Delete column
body: <p>I am using iTextSharp to export a gridview to PDF however I have a column that I would like to not include as it contains a hyperlink for the value. In the gridview in my program I replace the hyperlink with the text 'Details' for every row when displayed. The PDF just doesn't need this column. I have tried - </p>
  
  <pre><code>    grdResults.Columns.RemoveAt(11)
      grdResults.DataBind()
  </code></pre>
  
  <p>and</p>
  
  <pre><code>    grdResults.Columns(11).Visible = False
  </code></pre>
  
  <p>before the</p>
  
  <pre><code>    Dim pdfTable As New PdfPTable(grdResults.HeaderRow.Cells.Count)
  </code></pre>
  
  <p>this is the code I am working with</p>
  
  <pre><code>   Protected Sub grdResults_RowDataBound(ByVal sender As Object, ByVal e   As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdResults.RowDataBound
          If (e.Row.RowType = DataControlRowType.DataRow) Then
              Dim newHyperLink As New HyperLink()
              newHyperLink.Text = "Details"
              newHyperLink.NavigateUrl = "Details.aspx" &amp; Server.HtmlDecode(e.Row.Cells(11).Text)
              e.Row.Cells(11).Controls.Add(newHyperLink)
          End If
      End Sub
  
   Protected Sub btnPDF_Click(sender As Object, e As System.EventArgs) Handles btnPDF.Click
  
      Dim pdfTable As New PdfPTable(grdResults.HeaderRow.Cells.Count)
  
      For Each headerCell As TableCell In grdResults.HeaderRow.Cells
          Dim font As New Font()
          font.Color = New BaseColor(grdResults.HeaderStyle.ForeColor)
  
          Dim pdfCell As New PdfPCell(New Phrase(headerCell.Text, font))
          pdfCell.BackgroundColor = New BaseColor(grdResults.HeaderStyle.BackColor)
          pdfTable.AddCell(pdfCell)
  
      Next
  
      For Each gridViewRow As GridViewRow In grdResults.Rows
  
          For Each tableCell As TableCell In gridViewRow.Cells
              Dim font As New Font()
              font.Color = New BaseColor(grdResults.RowStyle.ForeColor)
  
              Dim pdfCell As New PdfPCell(New Phrase(tableCell.Text, font))
              pdfCell.BackgroundColor = New BaseColor(grdResults.RowStyle.BackColor)
              pdfTable.AddCell(pdfCell)
          Next
  
      Next
  
      Dim pdfDocument As New Document(iTextSharp.text.PageSize.A4, 10.0F, 10.0F, 10.0F, 10.0F)
      pdfDocument.SetPageSize(PageSize.A4.Rotate())
      PdfWriter.GetInstance(pdfDocument, Response.OutputStream)
      pdfDocument.Open()
      pdfDocument.Add(pdfTable)
      pdfDocument.Close()
      Response.ContentType = "application/pdf"
      Response.AppendHeader("content-disposition", "attachment, filename-results.pdf")
      Response.Write(PdfDocument)
      Response.Flush()
      Response.End()
  </code></pre>
  
  <p>Update - Thank-you for the code suggestions -- using the exclude by index that was posted below I was able to remove the hyperlink however the column was still there and the cell values shifted by one cell. What should have been the start of row two was now the last value in row one and so on. I changed the code to </p>
  
  <pre><code>            Idx += 1
  
              If Idx = 11 Then
                  tableCell.Text = "Details"
                  'Continue For
              End If
  </code></pre>
  
  <p>It now places the word "Details" in the column for every row however unlike the gridview and its hyperlink this column in the pdf is just taking up space. </p>