forum

Home / DeveloperSection / Forums / How to export selected data from my ASPx DevExpress gridview

How to export selected data from my ASPx DevExpress gridview

Mark Devid899809-Feb-2014

I need to export to XLS the selected row of my DevExpress GridView. When i try to export my grid, it creates an empty file. I think it is due to the callback that clear the data in my grid before exporting.

This is samples of my ASPx page.

The Load data button

 <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Styles/Images/load.png" onclick="ImageButton1_Click" />

The gridview

<dx:ASPxGridView ID="grid" ClientInstanceName="grid" runat="server" AutoGenerateColumns="False" KeyFieldName="car">

        <Columns>

            <dx:GridViewCommandColumn ShowSelectCheckbox="True" VisibleIndex="0" Caption="">

            </dx:GridViewCommandColumn>

            <dx:GridViewDataTextColumn Caption="Category" VisibleIndex="1" FieldName="category"

                Name="category" GroupIndex="0" SortIndex="0" SortOrder="Ascending">

            </dx:GridViewDataTextColumn>

            <dx:GridViewDataTextColumn Caption="Car" VisibleIndex="2" FieldName="car" Name="car">

            </dx:GridViewDataTextColumn>

        </Columns>

        <SettingsPager PageSize="100">

        </SettingsPager>

        <Settings ShowFooter="True" />

        <GroupSummary>

            <dx:ASPxSummaryItem FieldName="car" SummaryType="Count" />

        </GroupSummary>

    </dx:ASPxGridView>

The GridExporter

    <dx:ASPxGridViewExporter ID="gridExport" runat="server" GridViewID="grid" ExportedRowType="Selected" />

The create file button

<dx:ASPxButton ID="createFile" runat="server" Text="Create File"      UseSubmitBehavior="False" OnClick="createFile_Click">

                    <Image Url="~/Styles/Images/save.png">

                    </Image>

    </dx:ASPxButton>

Now the code behind.

When I click the load button, i create fake datas for my tests.

    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)

    {

        CreateFakeData();

    }

I create my datas in a DataTable Object. And then i bind my dataTable with my grid.

grid.DataSource = fakes;

grid.DataBind();

Everything seem to works great but when i click the export button, nothing is exported.

    protected void createFile_Click(object sender, EventArgs e)

    {

        gridExport.WriteXlsToResponse();

    }

I followed the DevExpress tutoria to export selected rows in ASPl. But it seems that my page is refreshed so i loose the data binded with the grid before the export.


Updated on 09-Feb-2014

Can you answer this question?


Answer

1 Answers

Liked By