views:

25

answers:

1

Hey everyone,

So I've got the following column defined in my radgrid:

                <telerik:GridTemplateColumn DataField="Payment.Customer.FirstName" DataType="System.String"
                    HeaderText="First Name" SortExpression="Payment.Customer.FirstName" UniqueName="FirstName">
                    <ItemTemplate>
                        <asp:HyperLink ID="hypFirstName" runat="server" Target="_blank" Text='<%# ((PaymentIssue)Container.DataItem).Payment.Customer.FirstName %>'
                            NavigateUrl='<%# string.Format("~/CustomerAdmin/Customer_View.aspx?customerId={0}", ((PaymentIssue)Container.DataItem).Payment.CustomerId) %>'></asp:HyperLink>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>

Now, if I use the RadGrid MasterTableView.ExportToExcel() function; all is well. However; if I try MasterTableView.ExportToCSV(), the column is blank.

Any ideas on what could be causing this?

A: 

OK; I figured this out. Turns out I need to set the Text property on the GridDataItems before exporting.

Sample code below:

Export Buttons Click Method

protected void lnkExport_Click(object sender, EventArgs e)
        {
            var linkButton = (LinkButton)sender;
            switch (linkButton.CommandArgument)
            {
                case "Excel":
                    rgPaymentIssues.MasterTableView.ExportToExcel();
                    break;
                case "CSV":
                    PrepareRadGridForExport();
                    rgPaymentIssues.MasterTableView.ExportToCSV();
                    break;
                default:
                    break;
            }
        }

PrepareRadGridForExport snippet

foreach (GridDataItem gi in rgPaymentIssues.MasterTableView.Items)
            {
                var hypFirstName = (HyperLink) gi.FindControl("hypFirstName");
                gi["FirstName"].Text = hypFirstName.Text;
            }
Jim B