title: Accessing the data from the gridview to download a PDF document in asp.net
body: <pre><code>     FID            NAME    
       M001           Faculty1    download
       M002           Faculty2    download
       M003           Faculty3    download
  </code></pre>
  
  <p>The above shown is my grid view containing details of faculty and the download link indicates the pdf form of the faculty to be downloaded.</p>
  
  <pre><code>       va = (string)Session["FID"];
  
  
  
  
         protected void DownloadFile(object sender, EventArgs e)
  {
  
      DataRow dr = GetData("select * from Personal_det where FID ='"+va+"'").Rows[0];
      Document doc = new Document(PageSize.A4, 88f, 88f, 10f, 10f);
      Font NormalFont = FontFactory.GetFont("Arial", 12, Font.NORMAL, BaseColor.BLACK);
      using (System.IO.MemoryStream m = new System.IO.MemoryStream())
      {
          PdfWriter w = PdfWriter.GetInstance(doc, m);
          Phrase phrase = null;
          PdfPCell cell = null;
          PdfPTable table = null;
          BaseColor color = null;
          Paragraph para = null;
          Font times = null;
          BaseFont bfTimes = null;
  
  
  
          doc.Open();
          table = new PdfPTable(2);
  
          cell = PhraseCell(new Phrase("Faculty Profile", FontFactory.GetFont("Arial", 12, Font.UNDERLINE, BaseColor.BLACK)), PdfPCell.ALIGN_CENTER);
          //table.SpacingBefore = 20f;
  
          cell.Colspan = 2;
          table.AddCell(cell);
          cell = PhraseCell(new Phrase(), PdfPCell.ALIGN_CENTER);
          cell.Colspan = 2;
          cell.PaddingBottom = 30f;
  
  
          //FID
          table.AddCell(PhraseCell(new Phrase("Faculty Code:", FontFactory.GetFont("Arial", 8, Font.BOLD, BaseColor.BLACK)), PdfPCell.ALIGN_LEFT));
          table.AddCell(PhraseCell(new Phrase("mahe" + dr["FID"].ToString(), FontFactory.GetFont("Arial", 8, Font.NORMAL, BaseColor.BLACK)), PdfPCell.ALIGN_LEFT));
          cell = PhraseCell(new Phrase(), PdfPCell.ALIGN_CENTER);
          cell.Colspan = 2;
          cell.PaddingBottom = 10f;
          table.AddCell(cell);
  
          //Name
          table.AddCell(PhraseCell(new Phrase("Name:", FontFactory.GetFont("Arial", 8, Font.BOLD, BaseColor.BLACK)), PdfPCell.ALIGN_LEFT));
          table.AddCell(PhraseCell(new Phrase(dr["Name"].ToString(), FontFactory.GetFont("Arial", 8, Font.BOLD, BaseColor.BLACK)), PdfPCell.ALIGN_LEFT));
          cell = PhraseCell(new Phrase(), PdfPCell.ALIGN_CENTER);
          cell.Colspan = 2;
          cell.PaddingBottom = 10f;
          table.AddCell(cell);
  
  
          //Date of Birth
          table.AddCell(PhraseCell(new Phrase("Date of Birth:", FontFactory.GetFont("Arial", 8, Font.BOLD, BaseColor.BLACK)), PdfPCell.ALIGN_LEFT));
          table.AddCell(PhraseCell(new Phrase(Convert.ToDateTime(dr["DOB"]).ToString("dd MMMM, yyyy"), FontFactory.GetFont("Arial", 8, Font.NORMAL, BaseColor.BLACK)), PdfPCell.ALIGN_LEFT));
          cell = PhraseCell(new Phrase(), PdfPCell.ALIGN_CENTER);
          cell.Colspan = 2;
          cell.PaddingBottom = 10f;
          table.AddCell(cell);
  
          //Phone Number
          table.AddCell(PhraseCell(new Phrase("Phone Number:", FontFactory.GetFont("Arial", 8, Font.BOLD, BaseColor.BLACK)), PdfPCell.ALIGN_LEFT));
          table.AddCell(PhraseCell(new Phrase(Convert.ToInt64(dr["MobileNo"]).ToString(), FontFactory.GetFont("Arial", 8, Font.NORMAL, BaseColor.BLACK)), PdfPCell.ALIGN_LEFT));
          cell = PhraseCell(new Phrase(), PdfPCell.ALIGN_CENTER);
          cell.Colspan = 2;
          cell.PaddingBottom = 10f;
          table.AddCell(cell);
  
          //Mail Id
          table.AddCell(PhraseCell(new Phrase("Email ID:", FontFactory.GetFont("Arial", 8, Font.BOLD, BaseColor.BLACK)), PdfPCell.ALIGN_LEFT));
          table.AddCell(PhraseCell(new Phrase(dr["EmailId"].ToString(), FontFactory.GetFont("Arial", 8, Font.BOLD, BaseColor.BLACK)), PdfPCell.ALIGN_LEFT));
          cell = PhraseCell(new Phrase(), PdfPCell.ALIGN_CENTER);
          cell.Colspan = 2;
          cell.PaddingBottom = 10f;
          table.AddCell(cell);
  
          //Address
          table.AddCell(PhraseCell(new Phrase("Res Address:", FontFactory.GetFont("Arial", 8, Font.BOLD, BaseColor.BLACK)), PdfPCell.ALIGN_LEFT));
          phrase = new Phrase(new Chunk(dr["add1"] + "\n " + dr["add2"] + "\n " + dr["add3"] + "\n " + dr["Pincode"], FontFactory.GetFont("Arial", 8, Font.NORMAL, BaseColor.BLACK)));
          table.AddCell(PhraseCell(phrase, PdfPCell.ALIGN_LEFT));
          cell = PhraseCell(new Phrase(), PdfPCell.ALIGN_CENTER);
          cell.Colspan = 2;
          cell.PaddingBottom = 10f;
          table.AddCell(cell);
          table.SpacingAfter = 30f;
          doc.Add(table);
   }
  </code></pre>
  
  <p>My grid view code is shown below</p>
  
  <pre><code>           &lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
          DataSourceID="SqlDataSource1" 
           Width="294px" onselectedindexchanged="GridView1_SelectedIndexChanged"  
  
           &gt;
          &lt;Columns&gt;
              &lt;asp:BoundField DataField="FID" HeaderText="FID" SortExpression="FID" /&gt;
              &lt;asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" /&gt;
             &lt;asp:TemplateField ItemStyle-HorizontalAlign="Center"&gt;
                  &lt;ItemTemplate&gt;
                      &lt;asp:LinkButton ID="lnkDownload" runat="server" 
  
        CommandArgument="&amp;lt;(&amp;quot;Value&amp;quot;)&amp;gt;" OnClick="DownloadFile"
  
                          Text="Download" /&gt;
                  &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
  
  
  
  
          &lt;/Columns&gt;
      &lt;/asp:GridView&gt;
      &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" 
          ConnectionString="&lt;%$ ConnectionStrings:ProjectConnectionString %&gt;" 
          SelectCommand="SELECT [FID], [Name] FROM [Personal_det]"&gt;
      &lt;/asp:SqlDataSource&gt;
  </code></pre>
  
  <p>The problem arises is whenver i click the download button the PDF of 1st faculty is been displaying even if i click download button for other faculty also,I need to get data for every faculty How to do get the pdf?</p>
  
  <p>My requirement is that the paricular pdf should be downloaded for the particular FID and it shouldnot download only for the first FID.</p>