Showing posts with label Export Gridview. Show all posts
Showing posts with label Export Gridview. Show all posts

Saturday, August 31, 2013

RegisterForEventValidation can only be called during Render();

Introduction: in this post I will explain how we can solve the error “RegisterForEventValidation can only be called during Render();"

RegisterForEventValidation

Description:


Error occur when we try to Export the Data from Controls to Pdf, Excel, Word, CSV. To solve this error add  EnableEventValidation = "false" to @Page directive of .aspx page as shown below:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Gridview_SelectExportRow.aspx.cs" Inherits="Gridview_SelectExportRow" EnableEventValidation="false" %>

I hope it will resolve your problem.

Thursday, August 29, 2013

How to Export Selected rows of Gridview to Excel, Word and PDF in Asp.net

Introduction: In this article I have explained how to Export the Selected rows of Gridview to Excel, Word and PDF in asp.net.
Export Selected rows of Gridview

Description:

STUDENT_ID
int
STUDENT_NAME
varchar(50)
STUDENT_ADDRESS
varchar(50)
STUDENT_CLASS
varchar(50)

Here ID is autoincrement.
To Export Data we use the 3rd party Library. Here we use the iTextSharp DLL and reference. To download iTextSharp DLL click Here. Put the downloaded iTextSharp DLL in Bin folder and build the project/website and use namespace in .aspx.cs or .aspx.vb page.
In this exmaple user wil be able select/unselect all rows and can also select/unselect a single row to export. If user click on export button without select row than all data of Gridview will be exported.
Add a webform to project. Darg and drop the control Gridview, button etc. from Toolbox and desgin the .aspx as mention below:

Wednesday, August 7, 2013

How to Export Gridview Data to Word in Asp.net

Introduction: In this article I will explain how we can Export the Gridview Data to Word in Asp.net
Description:
Take a new website. Add a webform to website and design .aspx page as shown below:
<body>
    <form id="form1" runat="server">
    <div>
     <table>
    <tr><td>&nbsp;</td><td align="right">
        <asp:Button ID="Button1" runat="server" Text="Export To MS-WORD"
            onclick="Button1_Click" /></td></tr>
    <tr><td>&nbsp;</td><td> <asp:GridView ID="grdstudent" runat="server" AutoGenerateColumns="false" DataKeyNames="STUDENT_ID" DataSourceID="SqlDataSource1">
        <Columns>
        <asp:BoundField DataField="STUDENT_NAME" HeaderText="STUDENT NAME" />
        <asp:BoundField DataField="STUDENT_ADDRESS" HeaderText="STUDENT ADDRESS" />
        <asp:BoundField DataField="STUDENT_CLASS" HeaderText="STUDENT CLASS" />
        </Columns>
        </asp:GridView></td></tr>
    </table>
      

Sunday, August 4, 2013

How to Export Gridview Data to Excel in Asp.net

Introduction: In this article I will explain how we can Export the Gridview Data to Excel in Asp.net
Description:
Take a new website. Add a webform to website and design .aspx page as shown below:
<body>
    <form id="form1" runat="server">
    <div>
     <table>
    <tr><td>&nbsp;</td><td align="right">
        <asp:Button ID="Button1" runat="server" Text="Export To Excel"
            onclick="Button1_Click" /></td></tr>
    <tr><td>&nbsp;</td><td> <asp:GridView ID="grdstudent" runat="server" AutoGenerateColumns="false" DataKeyNames="STUDENT_ID" DataSourceID="SqlDataSource1">
        <Columns>
        <asp:BoundField DataField="STUDENT_NAME" HeaderText="STUDENT NAME" />
        <asp:BoundField DataField="STUDENT_ADDRESS" HeaderText="STUDENT ADDRESS" />
        <asp:BoundField DataField="STUDENT_CLASS" HeaderText="STUDENT CLASS" />
        </Columns>
        </asp:GridView></td></tr>
    </table>
      
        <asp:SqlDataSource ID="SqlDataSource1" runat="server"
            ConnectionString="<%$ ConnectionStrings:TestBlogConnectionString %>"
            SelectCommand="SELECT * FROM [STUDENT_DETAIL]"></asp:SqlDataSource>
    </div>
    </form>
</body>

Monday, July 29, 2013

A page can have only one server-side Form tag.

Introduction: In this post I have explained how we can solve the problem A page can have only one server-side Form tag.

server-side

Description:
I got this error when I try to export the Gridview web page Data with images to Pdf file. To solve this error add EnableEventValidation = "false" to @Page directive of .aspx page as shown below:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ExportGrdiview_ImagesPDF.aspx.cs" Inherits="ExportGrdiview_ImagesPDF" EnableEventValidation = "false" %>


I hope it will resolve your problem.

Friday, July 19, 2013

How to Export Gridview Data to PDF in Asp.net

Introduction: in this article I will explain how we can Export the Gridview Data to PDF in Asp.net
Description:
Data Export feature is unavailable in Asp.net so we use the 3rd party Library. Here we use the iTextSharp DLL and reference. To download iTextSharp DLL Click Here.
Take a new website. Put the downloaded iTextSharp DLL in Bin folder and build the project/website. Add a webform to website and design .aspx page as shown below:

<body>
    <form id="form1" runat="server">
    <div>
    <table>
    <tr><td>&nbsp;</td><td align="right">
        <asp:Button ID="Button1" runat="server" Text="Export To PDF"
            onclick="Button1_Click" /></td></tr>
    <tr><td>&nbsp;</td><td> <asp:GridView ID="grdstudent" runat="server" AutoGenerateColumns="false" DataKeyNames="STUDENT_ID" DataSourceID="SqlDataSource1">
        <Columns>
        <asp:BoundField DataField="STUDENT_NAME" HeaderText="STUDENT NAME" />
        <asp:BoundField DataField="STUDENT_ADDRESS" HeaderText="STUDENT ADDRESS" />
        <asp:BoundField DataField="STUDENT_CLASS" HeaderText="STUDENT CLASS" />
        </Columns>
        </asp:GridView></td></tr>
    </table>
      

Saturday, July 13, 2013

How to Export Gridview Data to CSV in Asp.net

Introduction: In this article I will explain how we can Export the Gridview Data to CSV in Asp.net
Description:
In last article I have explained How to Bind Gridview in Asp.net.

Take a new website. Add a webform to website and design .aspx page as shown below:
<body>
    <form id="form1" runat="server">
    <div>
     <table>
    <tr><td>&nbsp;</td><td align="right">
        <asp:Button ID="Button1" runat="server" Text="Export To CSV"
            onclick="Button1_Click" /></td></tr>
    <tr><td>&nbsp;</td><td> <asp:GridView ID="grdstudent" runat="server" AutoGenerateColumns="false" DataKeyNames="STUDENT_ID" DataSourceID="SqlDataSource1">
        <Columns>
        <asp:BoundField DataField="STUDENT_NAME" HeaderText="STUDENT NAME" />
        <asp:BoundField DataField="STUDENT_ADDRESS" HeaderText="STUDENT ADDRESS" />
        <asp:BoundField DataField="STUDENT_CLASS" HeaderText="STUDENT CLASS" />
        </Columns>
        </asp:GridView></td></tr>
    </table>
      
        <asp:SqlDataSource ID="SqlDataSource1" runat="server"
            ConnectionString="<%$ ConnectionStrings:TestBlogConnectionString %>"
            SelectCommand="SELECT * FROM [STUDENT_DETAIL]"></asp:SqlDataSource>
    </div>
    </form>
</body>