This is a migrated thread and some comments may be shown as answers.
Grid Exporting to Excel
4 Answers 49 Views
This is a migrated thread and some comments may be shown as answers.
Hector Hernandez
Top achievements
Rank 2
Hector Hernandez asked on 21 Apr 2014, 02:54 AM
Hello.
i have this issue, i have a RadGrid i populate with then event NeedDataSource, then i change some value of cells with the event ItemDataBound, but when i want to export the grid only export the columns that i fill wih NeedDataSource event.
is there a way to put also the other columns that i have modify with ItemDataBound


thanks in advance.
Hector

4 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 21 Apr 2014, 05:17 AM
Hello,

Please try with the below code snippet.

protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
{
    if (e.CommandName.Equals(RadGrid.ExportToExcelCommandName))
    {
        foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
        {
            item["YourColumnUniqueName"].Text = "YourNewValue";
        }
    }
}

There is not such type of issue exists in RadGrid. But if you want to change the value before export then please use above code snippet.

Let me know if any concern.

Thanks,
Jayesh Goyani
0
Hector Hernandez
Top achievements
Rank 2
answered on 22 Apr 2014, 06:12 PM
Thanks Jayesh
the code that you post dont work for me,
i call the export event from a asp.imagebutton
here the code how i do:

string alternateText = (sender as ImageButton).AlternateText;
            GrdRegion.ExportSettings.Excel.Format = (GridExcelExportFormat)Enum.Parse(typeof(GridExcelExportFormat), alternateText);
            GrdRegion.ExportSettings.ExportOnlyData = true;
            GrdRegion.MasterTableView.GetColumn("EmpRnf").Display = true;
            GrdRegion.ExportSettings.FileName = "dd";
            GrdRegion.ExportSettings.OpenInNewWindow = true;
            GrdRegion.MasterTableView.ExportToExcel();

hope you can help me.
0
Accepted
Princy
Top achievements
Rank 1
answered on 23 Apr 2014, 06:52 AM
Hi Hector Hernandez,

It is hard to identify the issue with so less information, please provide your full code snippet. Meanwhile check the below sample code snippet and try to resolve the issue.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" DataSourceID="SqlDataSource1" AllowPaging="true" OnItemDataBound="RadGrid1_ItemDataBound">
    <MasterTableView DataKeyNames="OrderID" CommandItemDisplay="Top">
        <CommandItemTemplate>
            <br />
            <asp:ImageButton ID="imgbExport" runat="server" AlternateText="Export" OnClick="imgbExport_Click" />
            <br />
        </CommandItemTemplate>
        <Columns>
            <telerik:GridBoundColumn UniqueName="OrderID" DataField="OrderID" HeaderText="OrderID">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="ShipCity" HeaderText="ShipCity" UniqueName="ShipCity">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn UniqueName="EmployeeID" DataField="EmployeeID" HeaderText="EmployeeID">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="OrderDate" HeaderText="OrderDate" UniqueName="OrderDate">
            </telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT  * FROM [Orders]"></asp:SqlDataSource>

C#:
protected void imgbExport_Click(object sender, ImageClickEventArgs e)
{
    RadGrid1.ExportSettings.ExportOnlyData = true;      
    RadGrid1.ExportSettings.FileName = "FileName";
    RadGrid1.ExportSettings.OpenInNewWindow = true;
    RadGrid1.MasterTableView.ExportToExcel();
}
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem dataItem = (GridDataItem)e.Item;
        if (dataItem["EmployeeID"].Text=="3")
        {
            dataItem["ShipCity"].Text = "Null";
        }
    }
}

Thanks,
Princy
0
Hector Hernandez
Top achievements
Rank 2
answered on 25 Apr 2014, 06:06 PM
Thank Princy, it works!!!
Tags
Grid
Asked by
Hector Hernandez
Top achievements
Rank 2
Answers by
Jayesh Goyani
Top achievements
Rank 2
Hector Hernandez
Top achievements
Rank 2
Princy
Top achievements
Rank 1
Share this question
or