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

Export to ExcelML and boolean field

4 Answers 181 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jorge
Top achievements
Rank 1
Jorge asked on 13 Jul 2009, 06:23 PM
I rename boolean values in ItemDataBound and is shown correctly in the web browser, but when exporting to Excel boolean values are exported as true/false.
 
  protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        GridDataItem item = e.Item as GridDataItem; 
        if ((item != null) && (e.Item is GridDataItem)) 
        { 
            bool bValue = (bool)DataBinder.Eval(item.DataItem, "myfield"); 
            item["myfield"].Controls.Clear(); 
            item["myfield"].Text = ((bValue) ? "Yes" : "No"); 
 
  .... 

Thanks!
 

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 14 Jul 2009, 05:02 AM
Hi Jorge,

Try renaming the boolean values in the Click event of the Export button and see whether it is getting exported as expected.

CS:
 
protected void Button2_Click(object sender, EventArgs e) 
    { 
        RadGrid1.ExportSettings.ExportOnlyData = true
        RadGrid1.ExportSettings.OpenInNewWindow = true
        foreach (GridDataItem item in RadGrid1.MasterTableView.Items) 
        { 
            if (item["myfield"].Text == "True"
                item["myfield"].Text = "Yes"
            else 
                item["myfield"].Text = "No"
        } 
    
        RadGrid1.MasterTableView.ExportToExcel(); 
    } 


Thanks
Shinu.



0
Jorge
Top achievements
Rank 1
answered on 14 Jul 2009, 11:22 AM
I tried your code but items are already renamed to Yes/No, and RadGrid keeps on exporting them to true/false.

Thanks!
0
Accepted
Shinu
Top achievements
Rank 2
answered on 15 Jul 2009, 06:31 AM
Hi Jorge,

One another suggestion will be to modify the Select query for the Grid so that the boolean field will show desired text. Here is a sample select query. You may alter the select query according to your requirement.

CS:
 
SqlDataAdapter adp = new SqlDataAdapter("SELECT ProductName,'Discontinued' = CASE WHEN Discontinued = '1' THEN 'Yes' ELSE 'No' END FROM Products", conn); 
            DataSet ds = new DataSet(); 
            adp.Fill(ds,"GridData"); 
            RadGrid1.DataSource = ds; 

Regards
Shinu.
0
Jorge
Top achievements
Rank 1
answered on 15 Jul 2009, 10:30 AM
The query modification will work but what about the boolean problem in RadGrid? Should I report it as a bug or it's the expected behavior?

Thanks a lot.
Tags
Grid
Asked by
Jorge
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Jorge
Top achievements
Rank 1
Share this question
or