locked
Excel download for a full webform RRS feed

  • Question

  • User219039814 posted

    I have a set of textboxes and 2 gridview, whose data is generated dynamically.

    Now i want to give download option, like a recepit format for the above data.

    is it possible.

    Tuesday, June 12, 2018 6:46 AM

All replies

  • User-330142929 posted

    Hi Vijaylakshmi,

    I have a set of textboxes and 2 gridview, whose data is generated dynamically.

    According to your description, I am not clear about your requirement. In my opinion, You seem to be wondering how to download dynamically generated gridviews by Excel. If I understand it wrong, please provide more details about your requirements to let me know and provide an effective solution will be easier.

    The following is my workaround, I hope it helps you. In the following demo program, I dynamically generate a GridView using button click events. Use the jquery plugin table2excel.js to export excel.

    Aspx.

       <div runat="server" id="div1" style="border: 1px dashed #ff6a00;">
            </div>
            <hr />
            <asp:Button ID="Button2" runat="server" Text="Generate" OnClick="Button2_Click" />
            <asp:Button ID="Button1" runat="server" Text="Download" />

    Script.

    <script src="Scripts/jquery-3.3.1.min.js"></script>
        <script src="Scripts/jquery.table2excel.min.js"></script>
        <script type="text/javascript">
            $(function () {
                $("#Button1").click(function(){ 
                console.log(1) 
                $("#GridView1").table2excel({ 
                    exclude: ".noExl", 
                    name: "Excel Document Name", 
                    filename: "myFileName", 
                    exclude_img: true, 
                    exclude_links: true, 
                    exclude_inputs: true
                });
            })
            })
    </script>

    Code behind.

      protected void Button2_Click(object sender, EventArgs e)
            {
                GridView gridView = new GridView();
                gridView.ID = "GridView1";
                gridView.DataSource = GetDataTable();
                gridView.DataBind();
                this.div1.Controls.Add(gridView);
     
            }
            protected DataTable GetDataTable()
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("ID");
                dt.Columns.Add("Name");
                DataRow dr = dt.NewRow();
                dr[0] = 1;
                dr[1] = "Apple";
                dt.Rows.Add(dr);
                DataRow dr1 = dt.NewRow();
                dr1[0] = 2;
                dr1[1] = "Peach";
                dt.Rows.Add(dr1);
                return dt;
            }

    How it works.

    How to use jquery plugin table2Excel.js, GitHub project host address.

    https://github.com/rainabba/jquery-table2excel

    Please feel free to let me know if you have any question.

     

    Best Regards,

    Abraham

    Thursday, June 14, 2018 10:36 AM