I have declared a global variable in a class in c# as
public partial class admin_AnalyseQuery : System.Web.UI.Page
{
llvsMasterpage m;
private const string ASCENDING = " ASC";
private const string DESCENDING = " DESC";
DataTable dt;
Here i created a datatable dt as global variable right?
now the datatable dt is filled with the methods as in the screen shots
“BindDatagvAnalyse ” – this is a method to bind data to the grid view.
private void BindDatagvAnalyse()
{
Guid SchoolID = Guid.Parse(School.SelectedValue);
Guid YearID = Guid.Parse(Years.SelectedValue);
Guid VersionID = Guid.Parse(Versions.SelectedValue);
Guid LessonID = Guid.Parse(Lessons.SelectedValue);
Guid TeacherID = Guid.Parse(Teachers.SelectedValue);
Guid LearningunitID = Guid.Parse(Learningunits.SelectedValue);
Guid DomainID = Guid.Parse(Domain.SelectedValue);
pnllbl.Visible = true;
string Schoolname = School.SelectedItem.Text;
string Yearname = Years.SelectedItem.Text;
string Versionname = Versions.SelectedItem.Text;
string Lessonnmae = Lessons.SelectedItem.Text;
string Teachername = Teachers.SelectedItem.Text;
string Learningunitname = Learningunits.SelectedItem.Text;
string Domainname = Domain.SelectedItem.Text;
lblinfo.Text = Schoolname + "/" + Yearname + "/" + Lessonnmae + "/" + Versionname + "/" + Teachername + "/" + Domainname + "/" + Learningunitname;
// Guid PeriodID = Guid.Parse(Periods.SelectedValue);
dt = m.bussinesCollection.BussinesDomain.GetAllDetailsForgvanalyse(SchoolID, YearID, LessonID, VersionID, TeacherID, LearningunitID, DomainID);
int count = dt.Rows.Count;
lblcount.Text = count.ToString();
int c = m.bussinesCollection.BussinesDomain.GetAllDetailsForgvanalyseCount(SchoolID, YearID, LessonID, VersionID, TeacherID, LearningunitID, DomainID);
lblstd.Text = c.ToString();
gvAnalyse.DataSource = dt;
gvAnalyse.DataBind();
}
I have created this type of 6 methods which will create the table according to dropdowns selection and then call the according method and fill the gvanalyse accordingly which is displayed in screen.
Now i have put a button to create excel sheet from the table.
In the Export Excel button click event i have to create the Excel sheet with the table currently showing in screen.
For that in Button click event i have done this
protected void btnexel_Click(object sender, EventArgs e)
{
byte[] Result;
using (MemoryStream ms = new MemoryStream())
{
string school = School.SelectedItem.Text;
string year = Years.SelectedItem.Text;
DataTable final = dt;
// DataTable dt = m.bussinesCollection.BussinesDomain.GetAllDetailsForgvanalyse(SchoolID, YearID, LessonID, VersionID, TeacherID, LearningunitID, DomainID);
string style = @"<style> .textmode { mso-number-format:\@; } </style>";
Response.Write(style);
Result = ms.GetBuffer();
Session["Excel"] = Result;
Session["dt"] = final;
Session["school"] = school;
Session["year"] = year;
Session["pdf/excel"] = "excel/loondiest/analyse";
Response.Redirect("~/admin/DownloadPdf.aspx");
}
}
But when i debug it it always shows that table final & dt both are null.
What should i do?
You must persist your
DataTableinpersistance structure, because when you post your datas, your datas are lost.Persistance structure
Sample
Use Case :
Table =