roy himanshu

roy himanshu

  • NA
  • 126
  • 0

how to print gridview data when i click button in asp?

Nov 26 2009 11:21 PM

pz give the code help me
i got error my code past below
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

Answers (1)