Kanishka Gupta

Kanishka Gupta

  • NA
  • 8
  • 396

pass the value in lables from database and print in pdf

Feb 18 2019 11:55 PM
Hello Sir,
My name is Kanishka ,I generating admit card but i have some problem in that code
when i fill correct credential in textbox still it shows candidate not found.
Actually in this code , compiler does not consider if block , it compiles directly else condition and show the output "candidate not found ".
i am sending you my code. Please review it and give me some solution so that i can operate this code.
************************aspx code****************************************
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
text-align: center;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Panel ID="Pnl_login" runat="server">
<table class="style9" style="border:0px!important;">
<tr style="border:0px!important;">
<td class="style11" style="border:0px!important;"><asp:Label ID="lbl_CandidateName" runat="server" Text="Candidate's Name"></asp:Label>
</td>
<td style="border:0px!important;" class="style1">
<asp:TextBox ID="txt_CandidateName" runat="server" CssClass="style2" Height="46px"
style="font-weight: 700" Width="304px"></asp:TextBox>
</td>
</tr>
<tr style="border:0px!important;">
<td class="style11" style="border:0px!important;">
<asp:Label ID="lbl_FatherName" runat="server" Text="Father's Name"></asp:Label></td>
<td style="border:0px!important;" class="style1">
<asp:TextBox ID="txt_CFathersName" runat="server" CssClass="style2" Height="46px"
Width="304px"></asp:TextBox>
</td>
</tr>
<tr style="border:0px!important;">
<td class="style1" colspan="2" style="border:0px!important;">
<asp:Button ID="Button1" runat="server" Height="37px" onclick="Button1_Click"
Text="Show" Width="176px" Font-Names="Bodoni MT Black"
ForeColor="White" Font-Size="Medium" BackColor="#009933" BorderColor="#009933" />
</td>
</tr>
</table>
<asp:Label ID="ErrorMsg"
runat="server" style="color: #FF0000; font-weight: 700"></asp:Label>
</asp:Panel>
</div>
<div class="text-matter-holder">
<asp:Panel ID="Pnl_admit" runat="server" Height="412px">
<table class="style1" style="border:0px!important;">
<tr style="border:0px!important;">
<td class="style17"
style="border-style: none; border-color: inherit; border-width: 0px;">
<br />
<strong>???????:</strong> <span class="must-fill">?????? ??????</span><br />
<strong>???????</strong>: <span class="must-fill">www.company.gov.in</span><br />
<strong>????????? ?????</strong>: <span class="must-fill">25435348724</span><br />
<strong>???? ????</strong>: <span class="must-fill">[email protected]</span></td>
<td class="style18"
style="border-style: none; border-color: inherit; border-width: 0px;">&nbsp;&nbsp;&nbsp; Logo</td>
<td class="style3"
style="border-style: none; border-color: inherit; border-width: 0px;">
<span class="style2">
<strong>
<span class="style8">Company Name</span></strong></span><span
class="style8"><br /> </span><span class="style2"><strong>Area</strong>:
</span><span class="must-fill">South Delhi</span><span class="style2"><br />
<strong>Website</strong>: </span><span class="must-fill">www.company.gov.in</span><span
class="style2"><br /> <strong>HelpLine</strong> Number: </span>
<span class="must-fill">25435348724</span><span class="style2"><br /> <strong>Email
ID</strong>: <span class="must-fill">[email protected]</span></span>
</td>
</tr>
<tr style="border:0px!important;">
<td class="style5" colspan="3"
style="border-style: none; border-color: inherit; border-width: 0px;"><strong>
<br />
<span><span class="style14">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ? ?????? ?????????? /
E-admission Certificate</span></span><span class="style1"><br/> </span>
<span class="must-fill">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ???????????? ?? ?? 2019 </span>
</strong> <span class="must-fill"> <br /><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Post of Stenography 2019</strong></span><br /></td>
</tr>
<tr style="border:0px!important;">
<td class="style16"
style="border-style: none; border-color: inherit; border-width: 0px;"><strong><span class="style2">??????? ??????/Exam Time:</span><br>
<span class="must-fill">28/febuary/2019</span></strong></td>
<td class="style12"
style="border-style: none; border-color: inherit; border-width: 0px;"><strong>??????? ???? ?? ???/Repoting Time <span class="must-fill">
9:00AM </span> </strong></td>
<td class="style13"
style="border-style: none; border-color: inherit; border-width: 0px;"><strong>?????? ??? ???? ?? ???/ Entry Closing Time:
<span class="must-fill">10:00 A.M.</span></strong></td>
</tr>
<tr style="border:0px!important;"><td class="style4" style="border:0px!important;"><span class="style2"><strong>????? ?? ???/ Name of
Applicant's</strong> </span><asp:Label ID="lbl_ApplicantName" runat="server"
style="color: #FF0000"></asp:Label></td><td rowspan="3" style="border:0px!important;">
<asp:Image ID="Image2" runat="server" Height="115px" Width="145px" />
</td><td class="style7" style="border:0px!important;"><strong>???? /Gender</strong>&nbsp;<asp:Label
ID="lbl_Gendar" runat="server" style="color: #FF0000"></asp:Label>
</td></tr>
<tr style="border:0px!important;"><td class="style6" style="border:0px!important;"
rowspan="2"><span class="style2"><strong>??????? ?????? / Exam Center:</strong><strong
style="color: #FF0000"> Address of that company </strong>&nbsp;</span></td><td class="style15" style="border:0px!important;">
<strong>??????/ Category
<asp:Label ID="lbl_category" runat="server" style="color: #FF0000"></asp:Label>
</strong></td>
</tr>
<tr style="border:0px!important;"><td class="style7" style="border:0px!important;"><strong>????????/
Date of Birth
<asp:Label ID="lbl_DOB" runat="server" style="color: #FF0000"></asp:Label>
</strong></td></tr>
<tr style="border:0px!important;">
<td colspan="3" style="border:0px!important;">
<asp:Button ID="Button2"
runat="server" Text="Print" Height="35px" Width="95px" Font-Names="Bodoni MT Black"
ForeColor="White" Font-Size="Medium" BackColor="#009933" BorderColor="#009933"
onclick="Button2_Click"></asp:Button></td>
</tr>
</table>
</asp:Panel>
</div>
</form>
</body>
</html>
************************ C# Code *************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html.simpleparser;
using System.IO;
using System.Configuration;
public partial class admiitcard : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
//Pnl_admit.Visible = true;
//Pnl_login.Visible = false;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
string strConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection myConnect = new SqlConnection(strConnectionString);
string strCommandText = "SELECT CandidateName, Gender, Category, DOB FROM admitcard where CandidateName = '" + txt_CandidateName + "' and FatherName = '" + txt_CFathersName + "'";
SqlCommand cmd = new SqlCommand(strCommandText, myConnect);
myConnect.Open();
// SqlDataReader reader = cmd.ExecuteReader();
DataTable dt = new DataTable();
cmd.CommandType = CommandType.Text;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
Pnl_admit.Visible = true;
// Label3.Text = "Data Found";
lbl_CandidateName.Text = txt_CandidateName.Text;
lbl_FatherName.Text = txt_CFathersName.Text;
lbl_ApplicantName.Text = ds.Tables[0].Rows[1]["CandidateName"].ToString();
lbl_Gendar.Text = ds.Tables[0].Rows[2]["Gender"].ToString();
lbl_category.Text = ds.Tables[0].Rows[3]["Category"].ToString();
lbl_DOB.Text = ds.Tables[0].Rows[4]["DOB"].ToString();
}
else
{
ErrorMsg.Text = "Candidate Not Found";
}
con.Close();
}
protected void Button2_Click(object sender, EventArgs e)
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=GridViewData.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
Pnl_admit.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 10, 10, 0, 0);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
}
}

Attachment: admit.zip

Answers (1)