Export radgrid to pdf after filter tha radgrid data

2 posts, 0 answers
  1. krishna
    krishna avatar
    1 posts
    Member since:
    Nov 2010

    Posted 28 May 2012 Link to this post

    i am working with radgrid.
    when i am applying filtering on column and  then  export  to  excel or  pdf  then  there is  no  data  in  excel  sheet.
    please  solve the  issue

    page.aspx



    <asp:Button ID="dd" runat="server" Text="DD" OnClick="dd_Click" />
    <br />

    <script type="text/javascript">
        function onRequestStart(ajaxManager, eventArgs) {
            if (eventArgs.get_eventTarget().indexOf("dd") != -1)
                eventArgs.set_enableAjax(false);
        }
    </script>


        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <ClientEvents OnRequestStart="onRequestStart" />
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadGrid1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>

             <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="dd">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="dd" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <telerik:RadGrid ID="RadGrid1"  AllowSorting="True" AutoGenerateColumns="false"  AllowFilteringByColumn="True"
            GridLines="None" ShowGroupPanel="True" CssClass="RadGrid_Grid"
            AllowPaging="True" PageSize="10" runat="server" Width="95%"  OnNeedDataSource="RadGrid1_NeedDataSource"
           >

            <ClientSettings AllowColumnsReorder="True" AllowDragToGroup="True" ReorderColumnsOnClient="True"
              EnableRowHoverStyle="true">
                <Selecting AllowRowSelect="True" />
            </ClientSettings>
            <HeaderStyle CssClass="rgHeader"/>
            <ItemStyle CssClass="rgRow"/>
            <AlternatingItemStyle CssClass="rgAltRow"/>
            <ActiveItemStyle CssClass="rgActiveRow"/>
            <PagerStyle CssClass="rgPager"/>
            <SelectedItemStyle CssClass="rgSelectedRow"/>
            <GroupHeaderItemStyle CssClass="rgGroupHeaderItemRow"/>
            <FilterItemStyle CssClass="rgFilter" />
            <FooterStyle CssClass="rgFooter" />

            <ExportSettings HideStructureColumns="true" />
            <MasterTableView Width="100%" CommandItemDisplay="Top">
            
                <PagerStyle Mode="NextPrevNumericAndAdvanced" />
                <CommandItemSettings ShowExportToWordButton="true" ShowExportToExcelButton="true"
                    ShowExportToCsvButton="true" />
                    <Columns>
                  <telerik:GridTemplateColumn DataField="Employeeno" UniqueName="Employeeno" AutoPostBackOnFilter="true"
                        SortExpression="Employeeno" HeaderText="Employee No">
                        <ItemTemplate>
                            <a id="EmployeeEdit1" href='<%#DataBinder.Eval(Container,"DataItem.employeeId")%>'
                                onserverclick="EmployeeEdit" runat="server">
                                <%#Eval("Employeeno")%></a>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn DataField="firstName" UniqueName="firstName" AutoPostBackOnFilter="true"
                        SortExpression="firstName" HeaderText="First Name">
                        <ItemTemplate>
                            <a id="EmployeeEdit1" href='<%#DataBinder.Eval(Container,"DataItem.employeeId")%>'
                                onserverclick="EmployeeEdit" runat="server">
                                <%#Eval("firstName")%></a>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn DataField="lastName" UniqueName="lastName" AutoPostBackOnFilter="true"
                        SortExpression="lastName" HeaderText="Last Name">
                        <ItemTemplate>
                            <a id="EmployeeEdit0" href='<%#DataBinder.Eval(Container,"DataItem.employeeId")%>'
                                onserverclick="EmployeeEdit" runat="server">
                                <%#Eval("lastName")%></a>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>

                     <telerik:GridTemplateColumn DataField="designationName" UniqueName="designationName" AutoPostBackOnFilter="true"
                        SortExpression="designationName" HeaderText="Designation">
                        <ItemTemplate>
                            <a id="EmployeeEdit8" href='<%#DataBinder.Eval(Container,"DataItem.employeeId")%>'
                                onserverclick="EmployeeEdit" runat="server">
                                <%#Eval("designationName")%></a>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>

                    <telerik:GridTemplateColumn DataField="officeName" UniqueName="officeName" AutoPostBackOnFilter="true"
                        SortExpression="officeName" HeaderText="Office">
                        <ItemTemplate>
                            <a id="EmployeeEdit7" href='<%#DataBinder.Eval(Container,"DataItem.employeeId")%>'
                                onserverclick="EmployeeEdit" runat="server">
                                <%#Eval("officeName")%></a>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>

                    <telerik:GridTemplateColumn DataField="telephone" UniqueName="Home" AutoPostBackOnFilter="true"
                        SortExpression="telephone" HeaderText="Phone">
                        <ItemTemplate>
                            <a id="EmployeeEdit2" href='<%#DataBinder.Eval(Container,"DataItem.employeeId")%>'
                                onserverclick="EmployeeEdit" runat="server">
                                <%#Eval("telephone")%></a>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn DataField="extension" UniqueName="extension" AutoPostBackOnFilter="true"
                        SortExpression="extension" HeaderText="Extension">
                        <ItemTemplate>
                            <a id="EmployeeEdit3" href='<%#DataBinder.Eval(Container,"DataItem.employeeId")%>'
                                onserverclick="EmployeeEdit" runat="server">
                                <%#Eval("extension")%></a>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    
                     <telerik:GridTemplateColumn DataField="mobile" UniqueName="mobile" AutoPostBackOnFilter="true"
                        SortExpression="mobile" HeaderText="Mobile">
                        <ItemTemplate>
                            <a id="EmployeeEdit4" href='<%#DataBinder.Eval(Container,"DataItem.employeeId")%>'
                                onserverclick="EmployeeEdit" runat="server">
                                <%#Eval("mobile")%></a>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>

                    <telerik:GridTemplateColumn DataField="otherContact" UniqueName="otherContact" AutoPostBackOnFilter="true"
                        SortExpression="otherContact" HeaderText="Other Contact#">
                        <ItemTemplate>
                            <a id="EmployeeEdit6" href='<%#DataBinder.Eval(Container,"DataItem.employeeId")%>'
                                onserverclick="EmployeeEdit" runat="server">
                                <%#Eval("otherContact")%></a>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>

                    <telerik:GridTemplateColumn DataField="email" UniqueName="email" AutoPostBackOnFilter="true"
                        SortExpression="email" HeaderText="Email">
                        <ItemTemplate>
                            <a id="EmployeeEdit5" href='<%#DataBinder.Eval(Container,"DataItem.employeeId")%>'
                                onserverclick="EmployeeEdit" runat="server">
                                <%#Eval("email")%></a>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                </Columns>

            </MasterTableView>
        </telerik:RadGrid>




    page.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using BusinessLogicLayer;
    using BusinessEntity;
    using TimeWarner.Utility;
    using System.Web.UI.HtmlControls;
    using iTextSharp.text;
    using iTextSharp.text.pdf;
    using Telerik.Web.UI;
    using System.Data;
    using DataAccessLayer;
    using System.Text;
    using System.IO;
    using iTextSharp.text.html;
    using iTextSharp.text.html.simpleparser;
    namespace Timewarner
    {
        public partial class TestEmpDemo : System.Web.UI.Page
        {
            EmployeeBusiness objBizClass = new EmployeeBusiness();

            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    string error = string.Empty;
                    RadGrid1.DataSource = objBizClass.GetEmployee(ref error);
                    RadGrid1.DataBind();
                }
            }

            protected void dd_Click(object sender, EventArgs e)
            {

                ConfigureExport();
                RadGrid1.MasterTableView.ExportToExcel();
                //grvEmployee.ExportSettings.ExportOnlyData = true;
                //grvEmployee.ExportSettings.IgnorePaging = true;
                //grvEmployee.ExportSettings.OpenInNewWindow = true;
                //grvEmployee.MasterTableView.ExportToExcel();
                //grvEmployee.Rebind();
                //grvEmployee.MasterTableView.ExportToPdf();
            }

            public void ConfigureExport()
            {
                RadGrid1.ExportSettings.ExportOnlyData = true; ;
                RadGrid1.ExportSettings.IgnorePaging =true;
                RadGrid1.ExportSettings.OpenInNewWindow = true;
            }


            public void EmployeeEdit(object s, System.EventArgs e)
            {
                HtmlAnchor EmployeeEdit = (HtmlAnchor)s;
                string _ID = Convert.ToString(EmployeeEdit.HRef);
                Response.Redirect("edit-employee.aspx?ID=" + _ID);
            }
            protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
            {
                string error = string.Empty;
                RadGrid1.DataSource = objBizClass.GetEmployee(ref error);
            }
        }
    }



    Thanks & Regards

    Krishna Kant Singh
    +91 -9015873236
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 29 May 2012 Link to this post

    Hi Krishna,

    Try setting ExportOnlyData property of ExportSettings to false.

    C#:
    RadGrid1.ExportSettings.ExportOnlyData = false;

    Thanks,
    Shinu.
Back to Top