This is a migrated thread and some comments may be shown as answers.

Export to pdf,doc not working

1 Answer 63 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Parimal
Top achievements
Rank 1
Parimal asked on 17 Oct 2012, 10:14 AM


Hi,

I have created custom grid using item template grid .and have set show header to false.
however ,when I export i get to see header and no data which i want vice-versa ie:want ot show data and no header.


below is my code


<table width="100%" style="padding: 0px 30px 0px 30px">
        <tr style="padding-bottom: 10px;">
            <th style="background-color: #4C4C4C; margin-bottom: 30px; color: White; font-size: 13px;
                height: 25px; font-weight: bold" colspan="2">
                <div style="text-align: left; float: left; width: 20%">
                    Vacation Request
                </div>
                <div style="text-align: right; float: left; width: 80%">
                    <asp:ImageButton ID="imgexcel" runat="server" ImageUrl="~/Img/Export to excel.gif"
                        OnClick="imgexcel_Click" />
                    &nbsp;
                    <asp:ImageButton ID="imgword" runat="server" ImageUrl="~/Img/ExportToWord.gif" OnClick="imgword_Click" />
                    &nbsp;
                    <asp:ImageButton ID="imgpdf" runat="server" ImageUrl="~/Img/ExportToPDF.gif" OnClick="imgpdf_Click" />
                    &nbsp;
                    <asp:ImageButton ID="imgcsv" ImageUrl="~/Img/ExportToCSV.gif" runat="server" OnClick="imgcsv_Click" />
                </div>
            </th>
        </tr>
    </table>
    <table width="100%" style="padding: 0px 30px 0px 30px">
        <tr style="padding-bottom: 10px;">
            <td>
                <telerik:RadGrid ID="RadGrid1" runat="server">
                    <ExportSettings ExportOnlyData="true" FileName="VacationDetailReport" IgnorePaging="true"
                        OpenInNewWindow="true" HideStructureColumns="true" />
                    <MasterTableView TableLayout="Fixed" ShowHeader="false">
                        <CommandItemTemplate>
                        </CommandItemTemplate>
                        <ItemTemplate>
                            <table width="100%" style="padding: 0px 30px 0px 30px">
                                <tr>
                                    <td class="td1" width="20%" style="padding-top: 20px;">
                                        Consultant :
                                    </td>
                                    <td class="td2" style="padding-left: 6px">
                                        <asp:Label ID="lblConsultant" runat="server" Text='<%#Eval("name") %>' Font-Bold="true"></asp:Label>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="td1">
                                        Start Date :
                                    </td>
                                    <td class="td2" style="padding-left: 6px">
                                        <asp:Label ID="lblstartdate" runat="server" Font-Bold="true" Text='<%#Eval("StartDate") %>'></asp:Label>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="td1">
                                        End Date :
                                    </td>
                                    <td class="td2" style="padding-left: 6px">
                                        <asp:Label ID="lblEnddate" runat="server" Font-Bold="true" Text='<%#Eval("EndDate") %>'></asp:Label>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="td1">
                                        Type Of Leave :
                                    </td>
                                    <td class="td2" style="padding-left: 6px">
                                        <asp:Label ID="lblTypeofLeave" runat="server" Font-Bold="true" Text='<%#Eval("TypeOfLeave") %>'></asp:Label>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="td1">
                                        Additional Comments :
                                    </td>
                                    <td class="td2">
                                        <asp:Label ID="lblAdditionalComments" runat="server" Font-Bold="true" Text='<%#Eval("AdditionalComments") %>'></asp:Label>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="td1">
                                        Manager :
                                    </td>
                                    <td class="td2" style="padding-left: 6px">
                                        <%-- <asp:Label ID="lblManager" runat="server" Font-Bold="true" Text='<%Eval("") %>'></asp:Label>--%>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="td1">
                                        Emergency Contact Info :
                                    </td>
                                    <td class="td2">
                                        <asp:Label ID="LblEmergencyContactInfo" runat="server" Font-Bold="true" Text='<%#Eval("EmergencyContactInfo") %>'></asp:Label>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="text-align: right; padding-right: 5px; padding-top: 10px">
                                    </td>
                                    <td style="text-align: left; padding-left: 5px; padding-top: 10px">
                                    </td>
                                </tr>
                            </table>
                        </ItemTemplate>
                    </MasterTableView>
                </telerik:RadGrid>
            </td>
        </tr>
    </table>

1 Answer, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 19 Oct 2012, 02:15 PM
Hello Parimal,

In order to export the data in item template, you have to add a colgroup (with col elements) and also set the width of the table in pixels.
<table width="500px" style="padding: 0px 30px 0px 30px">
     <colgroup>
         <col span="2" />
     </colgroup>

As to the header you have to hook ItemCreated/ItemDataBound event handler, loop through all the headers and set their visible property to false:
bool isExport = false;
    protected void imgcsv_Click(object sender, EventArgs e)
    {
        isExport = true;
        RadGrid1.MasterTableView.ExportToPdf();
        RadGrid1.Rebind();
    }
 
    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridHeaderItem && isExport)
        {
            GridHeaderItem header = e.Item as GridHeaderItem;
            header.Visible = false;
        }
    }


All the best,
Kostadin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
General Discussions
Asked by
Parimal
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Share this question
or