Home > DeveloperSection > Forums > How to export selected data from my ASPx DevExpress gridview
Mark Devid
Mark Devid

Total Post:102

Points:714
Posted on    February-09-2014 11:16 PM

 C# C# 
Ratings:


 1 Reply(s)
 5370  View(s)
Rate this:

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.



Pravesh Singh

Total Post:411

Points:2881
Posted on    February-09-2014 11:44 PM

Hi Mark,

I had a similar situation when I was binding data to an ASPXGridView in the code behind. I was able to solve it by rebinding in the button click, before the export line.

protected void createFile_Click(object sender, EventArgs e)

{

    grid.DataSource = fakes;       

    grid.DataBind();       

    gridExport.WriteXlsToResponse();

}


Don't want to miss updates? Please click the below button!

Follow MindStick