DataTable dt = new DataTable(); // data structure to store the table from the database protected void Page_Load(object sender, EventArgs e) { string userName = Convert.ToString(Session["userName"]); //to get the userName from the session object userNameLabel.Text = userName + " , your Quiz Report is displayed below"; if (!IsPostBack) /*To avoid execution on page load*/ { score = Convert.ToString(Session["Counter"]); if (Session["Report"] != null) { report = Session["Report"] as List <string>; } dt.Columns.Add("Question Number"); dt.Columns.Add("Result"); for (int i = 0; i < report.Count(); i++) { dt.Rows.Add(i + 1, report[i]); } GridViewReport.DataSource = dt; GridViewReport.DataBind(); ScoreLabel.Text = "Total marks: " + score; } }
protected void LoadReport() { DataTable dt = new DataTable(); dt = dal.SelectAllInformation(); GridViewReport.DataSource = dt; GridViewReport.DataBind(); }
public void GetReport() { string getReport = "SELECT * FROM Report ORDER BY reportId DESC"; dt = da.ConnectDataBaseReturnDT(getReport); if (dt.Rows.Count > 0) { GridViewReport.DataSource = HttpUtility.HtmlEncode(dt); GridViewReport.DataBind(); } }
public void GenerateStudentsReportInExcel(int ClassID, int SessionID) { DataTable dtStudents; string constr = Connection.ConnectionString; using (SqlConnection con = new SqlConnection(constr)) { SqlCommand cmd = new SqlCommand(); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@SessionID", SessionID); cmd.Parameters.AddWithValue("@ClassID", ClassID); cmd.CommandText = "pICAS_RPT_GetStudentList_BySessionAndClass"; using (SqlDataAdapter sda = new SqlDataAdapter()) { cmd.Connection = con; sda.SelectCommand = cmd; using (DataTable dt = new DataTable()) { sda.Fill(dt); dt.TableName = "TSDC_" + ddlSession.Text.ToString() + "_Plus" + ClassID.ToString(); Response.ClearContent(); Response.AppendHeader("content-disposition", "attachment;filename=TSDC_Students_Report" + ddlSession.Text.ToString() + "_Plus" + ClassID.ToString() + ".xlsx"); Response.ContentType = "application/excel"; StringWriter sWriterObj = new StringWriter(); HtmlTextWriter htmlWriterObj = new HtmlTextWriter(sWriterObj); GridViewReport.DataSource = dt; GridViewReport.DataBind(); GridViewReport.RenderControl(htmlWriterObj); //GridViewReport.HeaderRow.Style.Add("background-color", "#ffffff"); //foreach (TableCell itemCell in GridViewReport.Rows) //{ // itemCell.Style["background-color"] = "#00ff00"; //} Response.Write(sWriterObj.ToString()); Response.End(); //using (XLWorkbook wb = new XLWorkbook()) //{ // string SheetName = string.Format("Sheet_{0}_plus_{1}", ddlSession.Text.ToString(), ClassID.ToString()); // wb.Worksheets.Add(dt, SheetName); // Response.Clear(); // Response.Buffer = true; // Response.Charset = ""; // Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; // Response.AddHeader("content-disposition", "attachment;filename=TSDC_Students_Report" + ddlSession.Text.ToString() + "_Plus" + ClassID.ToString() + ".xlsx"); // using (MemoryStream MyMemoryStream = new MemoryStream()) // { // wb.SaveAs(MyMemoryStream); // MyMemoryStream.WriteTo(Response.OutputStream); // Response.Flush(); // Response.End(); // } //} } //} } } }
protected void GridViewReport_PageIndexChanging(object sender, GridViewPageEventArgs e) { LoadReport(); GridViewReport.PageIndex = e.NewPageIndex; GridViewReport.DataBind(); }
private void BindGridView(string search) { GridViewReport.DataSource = da.GetEmployees(search); GridViewReport.DataBind(); }