Tech
Forums
Jobs
Books
Events
Videos
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
1
Answer
how to print gridview data when i click button in asp?
roy himanshu
15y
4.2k
1
Reply
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
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
how to print gridview data when i click a button?
add rows to the data gridview one by one on clicking a button at run time . how can i do it in c#.