hi,friends,
how to print gridview data when i click a button.plz help in asp
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
roy himanshuPosted Nov 26, 2009, 6:24 AM
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
Lalit MPosted Nov 26, 2009, 6:07 AM
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