how to generate seprately student data successfully?
private void BindSectionGrid()
{
con = new SqlDbConnect();
con.SqlQuery("select AdmissionNo,SName,FName,ClassName,SectionName,SPic from tblStdReg as sr inner join tblDefClass as dc on sr.ClassID=dc.ClassID inner join tblDefSection as ds on sr.SectionID=ds.SectionID where sr.ClassID=@CId and sr.SectionID=@SId order by AdmissionNo");
con.Cmd.Parameters.Add(new SqlParameter("@CId", this.ddlClass.SelectedValue)); // className= this.ddlClass.SelectedItem.Text
con.Cmd.Parameters.Add(new SqlParameter("@SId", this.ddlSection.SelectedValue));
adapt.SelectCommand = con.Cmd;
adapt.Fill(sTable);
if (sTable.Rows.Count > 0)
{
GridView1.DataSource = sTable;
GridView1.DataBind();
}
else
{
Response.Write("No Record Found");
return;
}
}
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string Id = GridView1.DataKeys[e.Row.RowIndex].Value.ToString();
GridView gvResult = e.Row.FindControl("gvResult") as GridView; // gvResult.DataSource = GetData(string.Format("select Convert ( Varchar (50) , Row_Number () Over (Order By sr.AdmissionNo ) ) as [Sr.No],ts.AdmissionNo,SubjectName,MaxMarks,Marks,Round((Marks) * 100/ (MaxMarks),1) as Percentage from tblSetMarks as ts inner join tblStdReg as sr on ts.AdmissionNo=sr.AdmissionNo inner join tblDefClass as dc on ts.ClassID=dc.ClassID inner join tblDefSection as ds on ts.SectionID=ds.SectionID inner join tblDefSubject as dsu on ts.SubjectID=dsu.SubjectID where sr.AdmissionNo='{0}'", Id));
gvResult.DataSource = GetData(string.Format("select Convert ( Varchar (50) , Row_Number () Over (Order By sr.AdmissionNo ) ) as [Sr.No],ts.AdmissionNo,SubjectName,MaxMarks,Marks,Round((Marks) * 100/ (MaxMarks),1) as Percentage,CASE WHEN Round((Marks) * 100/ (MaxMarks),1) >= 90 THEN 'A+' WHEN Round((Marks) * 100/ (MaxMarks),1) >= 80 THEN 'A' WHEN Round((Marks) * 100/ (MaxMarks),1) >= 70 THEN 'B' WHEN Round((Marks) * 100/ (MaxMarks),1) >= 60 THEN 'C' WHEN Round((Marks) * 100/ (MaxMarks),1) >= 50 THEN 'D' WHEN Round((Marks) * 100/ (MaxMarks),1) >= 40 THEN 'E' ELSE 'FAIL' END AS Grade,CASE WHEN Round((Marks) * 100/ (MaxMarks),1) >= 90 THEN 'OutStanding' WHEN Round((Marks) * 100/ (MaxMarks),1) >= 80 THEN 'Excellent' WHEN Round((Marks) * 100/ (MaxMarks),1) >= 70 THEN 'Very Good' WHEN Round((Marks) * 100/ (MaxMarks),1) >= 60 THEN 'Good' WHEN Round((Marks) * 100/ (MaxMarks),1) >= 50 THEN 'Satisfactory' WHEN Round((Marks) * 100/ (MaxMarks),1) >= 40 THEN 'Work Hard' ELSE 'FAIL' END AS Remarks,dense_rank() over(partition BY (MaxMarks) order by (Marks) DESC) AS Position from tblSetMarks as ts inner join tblStdReg as sr on ts.AdmissionNo=sr.AdmissionNo inner join tblDefClass as dc on ts.ClassID=dc.ClassID inner join tblDefSection as ds on ts.SectionID=ds.SectionID inner join tblDefSubject as dsu on ts.SubjectID=dsu.SubjectID where sr.AdmissionNo='{0}'", Id));
gvResult.DataBind();
}
}
To generate result card in pdf file my code
protected void btnMultiple_Click(object sender, EventArgs e)
{
int i = 0;
string Reg = null;
string name = null;
string fname = null;
string Cls = null;
string Sec = null;
Byte[] bytess = null;
int j = 0;
string si = null;
string Subject = null;
string Totall = null;
string Obtained = null;
string Per = null;
string sgrade = null;
string sremarks = null;
string sposition = null;
string cposition = null;
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=TestReport.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Document doc = new Document(PageSize.A4);
PdfWriter writer = PdfWriter.GetInstance(doc, Response.OutputStream);
doc.Open();
try
{
DataTable dt = new DataTable("GridView_Data");
foreach (GridViewRow row in GridView1.Rows)
{
Reg = row.Cells[1].Text;
name = row.Cells[2].Text;
fname = row.Cells[3].Text;
Cls = row.Cells[4].Text;
Sec = row.Cells[5].Text;
PdfPTable table = new PdfPTable(8);
table.DefaultCell.Padding = 10f;
table.DefaultCell.BackgroundColor = iTextSharp.text.Color.WHITE;
table.DefaultCell.BorderColor = new iTextSharp.text.Color(191, 208, 247);
table.HorizontalAlignment = Element.ALIGN_CENTER;
table.TotalWidth = 500f;
table.LockedWidth = true;
PdfPTable nested = new PdfPTable(4);
float[] width = new float[] { 0.1f, 0.1f, 0.1f, 0.1f };
nested.SetWidths(width);
nested.DefaultCell.BackgroundColor = iTextSharp.text.Color.WHITE;
nested.DefaultCell.BorderColor = new iTextSharp.text.Color(191, 208, 247);
nested.DefaultCell.Padding = 10f;
nested.AddCell(new Phrase("Reg No.", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
nested.AddCell(new Phrase(Reg, FontFactory.GetFont(FontFactory.HELVETICA, 8)));
nested.AddCell(new Phrase("Session", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
nested.AddCell(new Phrase(ddlSession.SelectedItem.ToString(), FontFactory.GetFont(FontFactory.HELVETICA, 8)));
nested.AddCell(new Phrase("Student Name", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
nested.AddCell(new Phrase(name, FontFactory.GetFont(FontFactory.HELVETICA, 8)));
nested.AddCell(new Phrase("Assessment Term", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
nested.AddCell(new Phrase(ddlExam.SelectedItem.ToString(), FontFactory.GetFont(FontFactory.HELVETICA, 8)));
nested.AddCell(new Phrase("Father Name", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
nested.AddCell(new Phrase(fname, FontFactory.GetFont(FontFactory.HELVETICA, 8)));
nested.AddCell(new Phrase("Attendance", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
nested.AddCell(new Phrase("", FontFactory.GetFont(FontFactory.HELVETICA, 8)));
nested.AddCell(new Phrase("Class", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
nested.AddCell(new Phrase(Cls, FontFactory.GetFont(FontFactory.HELVETICA, 8)));
nested.AddCell(new Phrase("Section", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
nested.AddCell(new Phrase(Sec, FontFactory.GetFont(FontFactory.HELVETICA, 8)));
PdfPCell nesthousing = new PdfPCell(nested);
nesthousing.BackgroundColor = iTextSharp.text.Color.WHITE;
nesthousing.BorderColor = new iTextSharp.text.Color(191, 208, 247);
nesthousing.Colspan = 7;
nesthousing.Padding = 0f;
table.AddCell(nesthousing);
// iTextSharp.text.Image imag = iTextSharp.text.Image.GetInstance(bytess);
//imag.ScaleToFit(45F, 50F);
PdfPCell bottom = new PdfPCell();
bottom.Padding = 5f;
bottom.BackgroundColor = iTextSharp.text.Color.WHITE;
bottom.BorderColor = new iTextSharp.text.Color(191, 208, 247);
bottom.HorizontalAlignment = 1;
table.AddCell(bottom);
// GridView gvResult = (GridView)GridView1.Rows[1].FindControl("gvResult");
GridView gvResult = (row.FindControl("gvResult") as GridView);
PdfPCell head1 = new PdfPCell(new Phrase("Student Marks Detail", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
head1.BackgroundColor = new iTextSharp.text.Color(191, 208, 247);
head1.BorderColor = new iTextSharp.text.Color(191, 208, 247);
head1.Indent = 10;
head1.HorizontalAlignment = 1;
head1.Colspan = 8;
head1.Padding = 10;
table.AddCell(head1);
table.AddCell(new Phrase("Sr. No.", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
table.AddCell(new Phrase("Subjects", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
table.AddCell(new Phrase("Max Marks", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
table.AddCell(new Phrase("Obt Marks", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
table.AddCell(new Phrase("%age", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
table.AddCell(new Phrase("Grade", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
table.AddCell(new Phrase("Position", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
table.AddCell(new Phrase("Remarks", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
for (j = 0; j < gvResult.Rows.Count; j++)
{
dt.Rows.Add(row.Cells[1].Text, row.Cells[2].Text, row.Cells[3].Text, row.Cells[4].Text, row.Cells[5].Text, gvResult.Rows[j].Cells[0].Text, gvResult.Rows[j].Cells[1].Text, gvResult.Rows[j].Cells[2].Text, gvResult.Rows[j].Cells[3].Text, gvResult.Rows[j].Cells[4].Text, gvResult.Rows[j].Cells[5].Text, gvResult.Rows[j].Cells[6].Text, gvResult.Rows[j].Cells[7].Text);
si = gvResult.Rows[j].Cells[0].Text;
Subject = gvResult.Rows[j].Cells[1].Text;
Totall = gvResult.Rows[j].Cells[2].Text;
Obtained = gvResult.Rows[j].Cells[3].Text;
Per = gvResult.Rows[j].Cells[4].Text;
sgrade = gvResult.Rows[j].Cells[5].Text;
sremarks = gvResult.Rows[j].Cells[6].Text;
sposition = gvResult.Rows[j].Cells[7].Text;
table.AddCell(new Phrase(si, FontFactory.GetFont(FontFactory.HELVETICA, 7)));
table.AddCell(new Phrase(Subject, FontFactory.GetFont(FontFactory.HELVETICA, 7)));
table.AddCell(new Phrase(Totall, FontFactory.GetFont(FontFactory.HELVETICA, 7)));
table.AddCell(new Phrase(Obtained, FontFactory.GetFont(FontFactory.HELVETICA, 7)));
table.AddCell(new Phrase(Per, FontFactory.GetFont(FontFactory.HELVETICA, 7)));
table.AddCell(new Phrase(sgrade, FontFactory.GetFont(FontFactory.HELVETICA, 7)));
table.AddCell(new Phrase(sposition, FontFactory.GetFont(FontFactory.HELVETICA, 7)));
table.AddCell(new Phrase(sremarks, FontFactory.GetFont(FontFactory.HELVETICA, 7)));
Subject = gvResult.Rows[j].Cells[1].Text;
Totall = gvResult.Rows[j].Cells[2].Text;
Obtained = gvResult.Rows[j].Cells[3].Text;
Per = gvResult.Rows[j].Cells[4].Text;
sgrade = gvResult.Rows[j].Cells[5].Text;
sremarks = gvResult.Rows[j].Cells[6].Text;
sposition = gvResult.Rows[j].Cells[7].Text;
table.AddCell(new Phrase(si, FontFactory.GetFont(FontFactory.HELVETICA, 7)));
table.AddCell(new Phrase(Subject, FontFactory.GetFont(FontFactory.HELVETICA, 7)));
table.AddCell(new Phrase(Totall, FontFactory.GetFont(FontFactory.HELVETICA, 7)));
table.AddCell(new Phrase(Obtained, FontFactory.GetFont(FontFactory.HELVETICA, 7)));
table.AddCell(new Phrase(Per, FontFactory.GetFont(FontFactory.HELVETICA, 7)));
table.AddCell(new Phrase(sgrade, FontFactory.GetFont(FontFactory.HELVETICA, 7)));
table.AddCell(new Phrase(sposition, FontFactory.GetFont(FontFactory.HELVETICA, 7)));
table.AddCell(new Phrase(sremarks, FontFactory.GetFont(FontFactory.HELVETICA, 7)));
}
PdfPCell head2 = new PdfPCell(new Phrase("", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
// head2.BackgroundColor = new iTextSharp.text.Color(191, 208, 247);
head2.BorderColor = new iTextSharp.text.Color(191, 208, 247);
head2.Indent = 10;
head2.HorizontalAlignment = 1;
head2.Colspan = 8;
head2.Padding = 25;
table.AddCell(head2);
table.AddCell(new Phrase("Max Marks", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
// table.AddCell(new Phrase(Total.ToString(), FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
table.AddCell(new Phrase("", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
table.AddCell(new Phrase("Obt. Marks", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
//table.AddCell(new Phrase(marks.ToString(), FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
table.AddCell(new Phrase("", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
table.AddCell(new Phrase("% age", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
// table.AddCell(new Phrase(Convert.ToString(per) + " %", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
table.AddCell(new Phrase("", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
table.AddCell(new Phrase("Grade", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
// table.AddCell(new Phrase(grade.ToString(), FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
table.AddCell(new Phrase("", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
table.AddCell(new Phrase("Remarks", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
// table.AddCell(new Phrase(cRemarks.ToString(), FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
table.AddCell(new Phrase("", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
table.AddCell(new Phrase("Strength", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
table.AddCell(new Phrase("", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
table.AddCell(new Phrase("Position:", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
table.AddCell(new Phrase(cposition, FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
table.AddCell(new Phrase("-", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
table.AddCell(new Phrase("-", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
PdfPCell head7 = new PdfPCell(new Phrase("", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
head7.BorderColor = new iTextSharp.text.Color(191, 208, 247);
head7.Indent = 10;
head7.HorizontalAlignment = 1;
head7.Colspan = 8;
head7.Padding = 25;
table.AddCell(head7);
PdfPCell head3 = new PdfPCell(new Phrase("Principal Signature", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
head3.BorderColor = new iTextSharp.text.Color(191, 208, 247);
head3.Indent = 10;
head3.HorizontalAlignment = 1;
head3.Colspan = 3;
head3.Padding = 10;
table.AddCell(head3);
PdfPCell head4 = new PdfPCell(new Phrase("Incharge Signature:", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
head4.BorderColor = new iTextSharp.text.Color(191, 208, 247);
head4.Indent = 10;
head4.HorizontalAlignment = 1;
head4.Colspan = 3;
head4.FixedHeight = 75;
table.AddCell(head4);
PdfPCell head5 = new PdfPCell(new Phrase("Parents Signature", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
head5.BorderColor = new iTextSharp.text.Color(191, 208, 247);
head5.Indent = 10;
head5.HorizontalAlignment = 1;
head5.Colspan = 3;
//head5.Padding = 45;
head5.FixedHeight = 75;
table.AddCell(head5);
PdfPCell head6 = new PdfPCell(new Phrase("Teacher Remarks:", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 9)));
head6.BorderColor = new iTextSharp.text.Color(191, 208, 247);
head6.Indent = 1;
head6.HorizontalAlignment = 0;
head6.Colspan = 8;
head6.Padding = 20;
table.AddCell(head6);
doc.Add(table);
doc.NewPage();
}
doc.Close();
Response.Write(doc);
Response.End();
}
catch (Exception)
{
throw;
}
finally
{
doc.Close();
}
}
my out put screen shot
screenshot of Gridview