S Balaji

S Balaji

  • NA
  • 72
  • 1.3k

Export pdf user details using id in gridview print button

May 16 2018 3:13 AM
Hi I had a gridview page which it contains the users id,fname,lname and five more things. Secondly i had created a view button in each row to redirect to another page called detail page, to view the details of the particular user. Thirdly my requirement is i need one more button called print button so that the detail items to print as pdf with logo, footer, header to be inside the pdf page. I watch the link https://www.aspsnippets.com/Articles/Create-PDF-Report-from-database-in-ASPNet-using-C-and-VBNet.aspx
 
its covering my thoughts but not i exactly want, (I am new for the asp.net) and my code
  1. protected void Page_Load(object sender, EventArgs e)  
  2. {  
  3. if (!this.IsPostBack)  
  4. {  
  5. BindGridView();  
  6. }  
  7. }  
  8. private void BindGridView()  
  9. {  
  10. string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;  
  11. SqlConnection con = new SqlConnection(constr);  
  12. SqlCommand cmd = new SqlCommand("select * from details", con);  
  13. DataTable dt = new DataTable();  
  14. SqlDataAdapter da = new SqlDataAdapter(cmd);  
  15. da.Fill(dt);  
  16. GridView1.DataSource = dt;  
  17. GridView1.DataBind();  
  18. }  
  19. protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)  
  20. {  
  21. if (e.CommandName == "EditButton")  
  22. {  
  23. int index = Convert.ToInt32(e.CommandArgument);  
  24. GridViewRow row = GridView1.Rows[index];  
  25. Response.Redirect("~/SD/EditView.aspx?EmpNo=" + row.Cells[0].Text);  
  26. }  
  27. if (e.CommandName == "PrintButton")  
  28. {  
  29. int index = Convert.ToInt32(e.CommandArgument);  
  30. GridViewRow row = GridView1.Rows[index];  
  31. }  
  32. }  
need help.
Thanks.

Answers (1)