This is a migrated thread and some comments may be shown as answers.

Conditional Data Export

4 Answers 148 Views
Grid
This is a migrated thread and some comments may be shown as answers.
FISCAL
Top achievements
Rank 1
FISCAL asked on 05 Jan 2011, 09:43 AM
Hi,

Is is possible to have a conditional data export from the grid? For example let's assume we have a grid with 3 columns as shown below and "Export?" column will either have "Yes" or "No" value. If it has "Yes", that record has to be exported to excel else not?

ID  Name   Export?
1    Scott   Yes
2    Parker  No
3   Milan    Yes


Any help would be highly appreciated and wish you a very Happy New Year ahead.

Many thanks

M G


4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 05 Jan 2011, 10:09 AM
Hello,

Before exporting, you can iterate through each item and hide the items based on the condition.

For more on this please refer the following documentation.
Word/Excel export (HTML-based) [Hiding Items section].


Shinu.
0
FISCAL
Top achievements
Rank 1
answered on 05 Jan 2011, 10:13 AM
Hi,

I have thought so but that does not work. I have to display all records in the grid and it's only that during the export process some have to be removed.

I think the other option would be to have grid just for the sake of exporting data but make it hidden..not invisible though!

Cheers,
MG
0
Accepted
Shinu
Top achievements
Rank 2
answered on 05 Jan 2011, 11:14 AM
Hello,


Here I am pasting the code for what I suggested. Hope this would help you. :)

Code:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{     
    if (e.CommandName == RadGrid.ExportToExcelCommandName)
    {         
        foreach( GridDataItem item in RadGrid1.MasterTableView.Items )
        {
            if (item["Export"].Text.ToString() == "No")
            {
                item.Visible = false;
            }
        }
    }
}

happy new year.


-Shinu.
0
FISCAL
Top achievements
Rank 1
answered on 05 Jan 2011, 11:16 AM
Many thanks -  I hope it will solve my problem without having extract grid!

Cheers,
M G
Tags
Grid
Asked by
FISCAL
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
FISCAL
Top achievements
Rank 1
Share this question
or