hi,friends,
how to print gridview data when i click a button.plz help in asp
How to print gridview data when i click a button?
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Lalit MRank #1,186 · 1.5K reputationPosted Nov 26, 2009, 1:07 AM EST
Also you can use this code sample gridview data export in pdf then you can print it show this link
http://www.netomatix.com/development/gridviewprinting.aspx
roy himanshu98 reputationPosted Nov 26, 2009, 1:24 AM EST
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection myConnection = new SqlConnection("Data Source=HIMANSHU;Initial Catalog=try;Trusted_Connection=yes;");
SqlDataAdapter Sqlad = new SqlDataAdapter("SELECT * FROM gri", myConnection);
DataSet dsSupplier = new DataSet();
Sqlad.Fill(dsSupplier);
GridView1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Clear();
Response.AddHeader("content-disposition", "attachment; filename=SupplierList.xls");
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter WriteItem = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlText = new HtmlTextWriter(WriteItem);
GridView1.RenderControl(htmlText);
Response.Write(WriteItem.ToString());
Response.End();
}
i got below error
Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server.
plz help me