.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Writing data from Gridview to Excel spreadsheet

Posted By:      Posted Date: October 23, 2010    Points: 0   Category :ASP.Net

Found code to do this but get an error I cannot correct.

Error is:

Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server.

This statement gives me the error: gv.RenderControl(htw)

Any help is really appreciated.  I got this cod from other threads in here

Here is the asp and the vb code:

Main asp page:

<form id="form1" runat="server">
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
            AllowSorting="True" DataSourceID="SqlDataSource1" Width="809px">
                <asp:CommandField ShowDeleteButton="True" />

View Complete Post

More Related Resource Links

display data into GridView from excel sheet

I have to display data from excel sheet into my gridview and also I need to figure out a way to store data into excel files from my web page. I am using C# 3.5, VS 2008.

Creating an Excel Spreadsheet and Adding Data to It Programmatically

The Interoperability services make it veryeasy to work with COM Capable Applications such as Word and Excel. Thisarticle reveals using Excel from a managed application. Excel is thespreadsheet component of Microsoft Office 2000. The majority of Excelprogrammatic functionality is exposed through Automation via the typelibrary Excel9.olb. The intention of this article is to express that amanaged application can interrelate with Excel as a COM server.

Export Gridview data to Excel sheet


Hi ,

     I have a requirement where i need to export the gridview data to excel.My code export the data in excel that was fine.

But the enchancement needed now , I was exporting the 3 gridview in same excel sheet under the workbook.

Now i need to export the 3 grid view in 3 different sheet in the same workbook.

so can please tell or share the updated code in my below code ...

public void writeovrsummary()


        Response.Write("Overall Summary");
        //Response.Write("Report as of " + DateTime.Now.ToString("hh:mm ss tt"));

        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);

        SqlCommand com = MyConnection.CreateCommand();
        com.CommandText = "useroverall_Report";
        SqlParameter[] par = new SqlParameter[1];
        par[0] = new

String Data missing start from "+" When Export Data To Excel Using Gridview

Hi,I am exporting data from gridview to excel file.My problem is that for all the string which contain "+", the rest of data begining from it is missing in excel file.For example: PWE-WER+78, when exported it will become PWE-WER.Below is my code.                Response.ClearContent() Response.Buffer = True Response.AddHeader("Content-Disposition", "attachment;filename=" & "ExportedExcel.xls") Response.ContentType = "application/vnd.ms-excel" Response.Charset = "" lobjStringWriter = New StringWriter lobjHtmlWriter = New HtmlTextWriter(lobjStringWriter) dgdResult.RenderControl(lobjHtmlWriter) Response.Write(lobjStringWriter.ToString()) Response.End() I  have search through online but no solution.Does anyone has idea on this?

Adding data from Excel spreadsheet to SQL table

This is not a programming question, I simply have a lot of data in two columns in an excel spreadsheet of data that I gathered.  I want to copy and paste this (manually) into a table that I have created in my ASPNETDB in my ASP.NET web application.  I thought it'd be as easy as copy the column, and hit paste in the "table data" view, but it's not (it only pastes one cell).Is there a way for me to manually copy data from excel and paste it in a table in my SQL Server?Thanks in advance! :)

excel to gridview, lost data?!

I don't know why.... I can't understand I import by fileupload one xls, I open this one and I would connect it to a gridview.Everythings works fine but when I see the gridview I don't understand why some data is not available  HttpPostedFile xls = this.FileUpload1.PostedFile; string strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + xls.FileName.ToString() + ";Extended Properties=Excel 8.0"; DataTable dt = new DataTable(); DataSet ds = new DataSet(); OleDbConnection oConn = new OleDbConnection(); oConn.ConnectionString = strConn; oConn.Open(); List<string> fogli = new List<string>(); //recupero i nomi dei fogli del file excel dt = oConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,null); foreach (DataRow tt in dt.Rows) { fogli.Add(tt["TABLE_NAME"].ToString()); } dt.Clear(); System.Data.OleDb.OleDbDataAdapter ExcelAdapter = new System.Data.OleDb.OleDbDataAdapter("SELECT * FROM [" + fogli[162].ToString() + "]", oConn); ExcelAdapter.Fill(ds); gvExcel.DataSource = ds.Tables[0].DefaultView; gvExcel.DataBind();First I get the name of all the sheets and after I fill one

How do I display excel, pdf and word binary data in a gridview?


Hello forum

I'm using the following code to upload images, pdf files, word files and excel to a sql table as binary data.  However, I can only figure out how to display the images but am clueless about the other type of files.  What adjustments do I need to make so that with a button click I can access the other files?  't By the way, I'm using an image control to display the binary data and I'm aware that that will only work to display images, I just don't how to access all the other types of files once uploaded. Thanks

Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.Data.SqlClient
Imports System.IO

Partial Class Uploads_UReceipts
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Request.QueryString("ImageID") IsNot Nothing Then

            Dim strQuery As String = "select Name, ContentType, Data from tblFiles where id=@id"

            Dim cmd As SqlCommand = New SqlCommand(strQuery)

            cmd.Parameters.Add("@id", SqlDbType.Int).Va

export the gridview data to excel problem



i am using master page and child pages in the child page

i want to export the gridview data to excel sheet for this i use the following code


        Response.AddHeader("content-disposition", "attachment; filename=shedules.xls");

        Response.ContentType = "application/excel";

        StringWriter sw = new StringWriter();

        HtmlTextWriter htw = new HtmlTextWriter(sw);




but in the gridShedules.RenderControl(htw) i got the following error but the form tag with  runat= server is already in the master page how to solve this issue

error:Control 'ctl00_ContentPlaceHolder1_grdshedules' of type 'GridView' must be placed inside a form tag with runat=server.

Error inserting data in Excel spreadsheet from SQL 2005 SP



I am using a SP on a SQL 2005 server to insert data into an Excel spreadsheet.

If I run the following query:



INTO OPENDATASOURCE('Microsoft.ACE.OLEDB.12.0','Data Source ="\\wvns01\data\Finance\ZIP\FY2011_testZIP\BankFile.xls";extended Properties=Excel 8.0')...

Reading and Writing Data to/from Excel File


I need to read and write data from excel sheet. Firstly for example I need to use the concept of accessing workgroup, sheet and then cells whatever I want.

For example I need to use cell A1+B1 and put the result in C1

alternatively I can use the same function above and put data in some other sheet of same excel file.

Please reply the answer either using C#.NET or asp.net using C#.NET

How to export data to excel from gridview and DataTable using asp.net?

In this article we will see how to export data from gridview control and dataTable to excel file in a simple way.

Editing the Data in a GridView

In addition to deleting a GridView's underlying data, another common need is to allow end users to edit the data displayed in a GridView. With ASP.NET 1.x's DataGrid control, editing the data is certainly possible, but requires creating three event handlers and writing a dozen or so lines of code. With the GridView and ASP.NET 2.0, it is possible to create an editable GridView without writing a single line of code! All of the necessary functionality is encapsulated within the GridView.

The GridView allows editing on a row-by-row basis. An editable GridView contains an additional column with an Edit button in each row. When the end user clicks on an Edit button that row becomes editable, causing the Edit button to change to Update and Cancel buttons and the other columns to become TextBoxes. The end user can then update one or more column values and click Update to save their changes.

Display data in gridview dynamicallay

I have AD domain which has 100000 users, I want to display all the users in gridview controls.Actually it is displaying users in gridview after parsing entire domain which takes around 30 min. I want to display the users while loading itself.It is continously getting user information from AD domain and getting each user details, I want to display the users information which already queried instead of waiting till getting all users information

asp.net display data in gridview

i want to display data in gridview binded to a sql datasource
but the problem part is i want to bind a field of that datasource to a dropdownlist and when a item is selected in that dropdownlist then correcposnding to that data will be displayed in gridview...

GridView control to show master-child or master-slave data, written in c#, asp.net

I previously made a master slave datagrid using Visual Studio 2003 .Net (original article) that would allow users to show data to clients using collapse and expand features. These features however did not carry over to gridview for many users. This tutorial will explaing how to create a collapsable/expandable gridview in frameworks 2.0 and higher

Easily manipulate data with the GridView control in ASP.NET 2.0

Last week, I introduced ASP.NET 2.0's GridView data control and covered the basics of using it. This week, I go a step further by going into the details of working with the data contained in the control. This includes viewing, editing, and deleting data. Thankfully, the GridView control makes it easy to utilize these features. Before diving into these topics, I begin with an examination of the different field types supported by the GridView control.

Display Related Data in an ASP.NET GridView

Typically when you display a datagrid you will want to show data from a related table. There are 3 different ways to accomplish this with NetTiers. You can use a custom stored procedure, deepload functionality from the code behind, or a strongly typed datasource control. We'll provide an example of each
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend