Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1775
Exporting TemplateDataField in pdf
posted

Normal 0 false false false MicrosoftInternetExplorer4

Hello!

How to export colums with type TemplateDataField  in pdf file by WebDocumentExporter?

 

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">


    <title></title>

</head>

<body>

    <form id="form1" runat="server">

    <div>   

        <ig:WebDataGrid ID="WebDataGrid1" runat="server" AutoGenerateColumns="False"

            Height="350px" Width="400px">

            <Columns>

                <ig:BoundDataField DataFieldName="index" Key="index">

                    <Header Text="index" />

                </ig:BoundDataField>

                <ig:BoundDataField DataFieldName="name" Key="name">

                    <Header Text="name" />

                </ig:BoundDataField>

                <ig:TemplateDataField Key="sex">

                    <Header Text="sex" />

                     <ItemTemplate>

                                <div style="text-align: center;"><asp:CheckBox runat="server" ID="key_" Checked='<%# DataBinder.Eval(Container, "DataItem.sex")%>'/></div>

                            </ItemTemplate>

                </ig:TemplateDataField>

            </Columns>

        </ig:WebDataGrid>

        <igtxt:WebImageButton ID="WebImageButton1" runat="server"

            onclick="WebImageButton1_Click" Text="pdf">

        </igtxt:WebImageButton>

        <ig:WebScriptManager ID="WebScriptManager1" runat="server">

        </ig:WebScriptManager>   

    </div>

    <ig:WebDocumentExporter ID="WebDocumentExporter1" runat="server"

        DownloadName="Mypdf.pdf">

    </ig:WebDocumentExporter>

    </form>

</body>

</html>



 cs file:

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data;

 

namespace WebApplication1

{

    public partial class MyPage : System.Web.UI.Page

    {

        protected void Page_Load(object sender, EventArgs e)

        {

            DataTable dt = new DataTable("MyTable");

            dt.Columns.Add("index", typeof(int));

            dt.Columns.Add("name", typeof(string));

            dt.Columns.Add("sex", typeof(bool));

 

            dt.Rows.Add(new object[] { 1, "Tom", true });

            dt.Rows.Add(new object[] { 2, "Ben", true });

            dt.Rows.Add(new object[] { 3, "Mary", false });

            dt.Rows.Add(new object[] { 4, "Kat", false });

            WebDataGrid1.DataSource = dt;

        }

        protected void WebImageButton1_Click(object sender, Infragistics.WebUI.WebDataInput.ButtonEventArgs e)

        {

            WebDocumentExporter1.Export(WebDataGrid1);

        }

    }

}  

result:


 

Thank you for help me!

Parents
  • 33839
    Suggested Answer
    posted

    Hi Sergey_Skalyga,

    In the future, if you have a question specificially about the WebDocumentExporter, you can post it in that forum.

    I tried out your little sample and got the same results.  What happens is that for templated cells, we attempt to render the template out as a string.  If we get an exception doing that, we return an empty string.  That is what is actually happening in this case because the checkbox has a runat attribute, so it needs to render in a form, not outside.  I tried a simple item template like <span>two</span> and it renders excactly that string out.  So, what you can do is handle cell exporting and set the value to true or false and it would at least say that.  Or you could add an image of a checked/unchecked checkbox to the cell.  In 11.1, there will be a bound checkbox that will automatically export the checked/unchecked/partial image.

    regards,
    David Young 

Reply Children
No Data