I am Abhimanyu Singh.. as i new in this field..i need help of you all.
Please help me to fetch/export the all Data of Data Base into excel sheet..
Actually i tried it with the help of Grid View Display but still its displaying only one/first page (visited page in grid) data.
And the big problem is that we do not want to display the Grid in designing page so I hide it(only taken a image button named "Export to Excel").
Exporting the All pages data into excel without any navigation in next page because as told it is hidden in designing page only i want on button click event.
protected void ImageButton5_Click(object sender, ImageClickEventArgs e)
{
con.Open();
SqlDataAdapter da3 = new SqlDataAdapter("Select applicant_id as 'Unique_ID', applicant_name as 'Name', father_name as 'Father Name', dob as 'Date of Birth', postal_address as 'Postal Address', pin as 'Pin', contact_no as 'Contact NO.', gender as 'Sex', marital as 'Marital', edu_quali as 'Qualification', email_id as 'Email ID', business_occupation as 'Occupation', experienced_fresher as 'Experience', audition_state as 'Audition State', audition_center as 'Center/ District', dd_cheq_no as 'Cheque No.', dd_cheq_date as 'Cheque Date', dd_cheq_amt as 'Cheque Amount', dd_cheq_bank as 'Bank', entry_date as 'Applied Date', form_place as 'Applied Place' from applicant_record", con);
DataSet ds3 = new DataSet();
da3.Fill(ds3);
DataTable dt3 = ds3.Tables[0];
GridView1.DataSource = dt3;
GridView1.DataBind();
con.Close();
// For Exporting into Excel sheet...........
Response.Clear();
Response.AddHeader("content-disposition", "attachment; filename=FileName.xls");
Response.Charset = "";
// If you want the option to "open only" the Excel file without "saving option"--then comment out the line below
//Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
GridView1.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
// Confirms that an HtmlForm control is rendered for the specified ASP.NET server control at run time.
}