protected void btnDownload_Click(object sender, EventArgs e) { try { Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=Report.xls"); Response.ContentType = "application/vnd.xls"; System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); GvTech.RenderControl(htmlWrite); Response.Write(stringWrite.ToString()); Response.End(); } catch (Exception ex) { throw ex; } }
protected void btnShow_Click(object sender, EventArgs e) { try { string Sql = "Select usrMobileno,Class,Division, RegBoys,RegGirls,Present_B, Present_G, EntryDate from " + " UDISE_StudentPresenty inner join UserMaster on UDISE_StudentPresenty.usrUserId=UserMaster.usrUserId where SchoolCode = " + Convert.ToString(SchoolCode) + " ";//'" + Convert.ToString(DateFormat) + "'"; if (ddlmonth.SelectedIndex != ddlmonth.Items.Count - 1) { Sql = Sql + " and datePart(month,UDISE_StudentPresenty.EntryDate)=" + ddlmonth.SelectedValue.ToString() + " "; } else if (txtDate.Text != "") { Sql = Sql + " and UDISE_StudentPresenty.EntryDate='" + txtDate.Text + "'"; } DataSet ds = cc.ExecuteDataset(Sql); gvItem.DataSource = ds.Tables[0]; gvItem.DataBind(); foreach (GridViewRow row in gvItem.Rows) { string Data = row.Cells[7].Text.ToString(); Data = DateSplit(Data); row.Cells[7].Text = Data; } for (int i = 0; i < gvItem.Rows.Count; i++) { Label lblPerb = (Label)gvItem.Rows[i].Cells[0].FindControl("lblPerBoy"); Label lblPerg = (Label)gvItem.Rows[i].Cells[0].FindControl("lblPerGirls"); Label lblAllStud = (Label)gvItem.Rows[i].Cells[0].FindControl("lblAllStud"); { double RegisterBoy = Convert.ToDouble(gvItem.Rows[i].Cells[3].Text); double RegisterGirls = Convert.ToDouble(gvItem.Rows[i].Cells[4].Text); double PresentBoy = Convert.ToDouble(gvItem.Rows[i].Cells[5].Text); double PresentGirls = Convert.ToDouble(gvItem.Rows[i].Cells[6].Text); if (RegisterBoy == 0.0 && RegisterGirls == 0.0) { lblPerb.Text = "0%"; lblPerg.Text = "0%"; lblAllStud.Text = "0%"; } else if (RegisterBoy == 0.0 && RegisterGirls != 0.0) { double k = 0.0; double j = PresentGirls / RegisterGirls; j = j * 100; double m = (PresentBoy + PresentGirls) / (RegisterBoy + RegisterGirls); m = m * 100; lblPerb.Text = Convert.ToInt16(k) + "%"; lblPerg.Text = Convert.ToInt16(j) + "%"; lblAllStud.Text = Convert.ToInt16(m) + "%"; } else if (RegisterBoy != 0.0 && RegisterGirls == 0.0) { double k = PresentBoy / RegisterBoy; k = k * 100; double j = 0.0; double m = (PresentBoy + PresentGirls) / (RegisterBoy + RegisterGirls); m = m * 100; lblPerb.Text = Convert.ToInt16(k) + "%"; lblPerg.Text = Convert.ToInt16(j) + "%"; lblAllStud.Text = Convert.ToInt16(m) + "%"; } else { double k = PresentBoy / RegisterBoy; k = k * 100; double j = PresentGirls / RegisterGirls; j = j * 100; double m = (PresentBoy + PresentGirls) / (RegisterBoy + RegisterGirls); m = m * 100; lblPerb.Text = Convert.ToInt16(k) + "%"; lblPerg.Text = Convert.ToInt16(j) + "%"; lblAllStud.Text = Convert.ToInt16(m) + "%"; } } } GvTech.DataSource = ds.Tables[0]; GvTech.DataBind(); for (int i = 0; i < GvTech.Rows.Count; i++) { Label lblPerb1 = (Label)GvTech.Rows[i].Cells[0].FindControl("lblPerBoy1"); Label lblPerg1 = (Label)GvTech.Rows[i].Cells[0].FindControl("lblPerGirls1"); Label lblAllStud1 = (Label)GvTech.Rows[i].Cells[0].FindControl("lblAllStud1"); { double RegisterBoy = Convert.ToDouble(GvTech.Rows[i].Cells[6].Text); double RegisterGirls = Convert.ToDouble(GvTech.Rows[i].Cells[7].Text); double PresentBoy = Convert.ToDouble(GvTech.Rows[i].Cells[8].Text); double PresentGirls = Convert.ToDouble(GvTech.Rows[i].Cells[9].Text); if (RegisterBoy == 0.0 && RegisterGirls == 0.0) { lblPerb1.Text = "0%"; lblPerg1.Text = "0%"; lblAllStud1.Text = "0%"; } else if (RegisterBoy == 0.0 && RegisterGirls != 0.0) { double k = 0.0; double j = PresentGirls / RegisterGirls; j = j * 100; double m = (PresentBoy + PresentGirls) / (RegisterBoy + RegisterGirls); m = m * 100; lblPerb1.Text = Convert.ToInt16(k) + "%"; lblPerg1.Text = Convert.ToInt16(j) + "%"; lblAllStud1.Text = Convert.ToInt16(m) + "%"; } else if (RegisterBoy != 0.0 && RegisterGirls == 0.0) { double k = PresentBoy / RegisterBoy; k = k * 100; double j = 0.0; double m = (PresentBoy + PresentGirls) / (RegisterBoy + RegisterGirls); m = m * 100; lblPerb1.Text = Convert.ToInt16(k) + "%"; lblPerg1.Text = Convert.ToInt16(j) + "%"; lblAllStud1.Text = Convert.ToInt16(m) + "%"; } else { double k = PresentBoy / RegisterBoy; k = k * 100; double j = PresentGirls / RegisterGirls; j = j * 100; double m = (PresentBoy + PresentGirls) / (RegisterBoy + RegisterGirls); m = m * 100; lblPerb1.Text = Convert.ToInt16(k) + "%"; lblPerg1.Text = Convert.ToInt16(j) + "%"; lblAllStud1.Text = Convert.ToInt16(m) + "%"; } } } } catch (Exception ex) { } }