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

checkbox value in radgrid is not exported to csv

8 Answers 145 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Amy Liu
Top achievements
Rank 1
Amy Liu asked on 07 Jul 2010, 08:52 PM
Hello!

I used the codes from 
http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/exporting/defaultcs.aspx

to export data in radgrid. But if I export to excel the top first line will have False False for filters with checkbox.

if I export to csv the checkbox values in csv are "", the True and False value in radgrid are not export into the csv.

I don't know why and couldn't find answer in the internet.

Please help. Thanks.
    <form id="form1" runat="server">  
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">  
          
    </telerik:RadScriptManager> 
    <telerik:RadCodeBlock runat="server">  
             <script type="text/javascript">  
                 function RowDblClick(sender, eventArgs) {  
                     sender.get_masterTableView().editItem(eventArgs.get_itemIndexHierarchical());  
                 }  
                   
                 function onRequestStart(sender, args) {  
                     if (args.get_eventTarget().indexOf("ExportToExcelButton") >= 0 ||  
                    args.get_eventTarget().indexOf("ExportToWordButton") >= 0 ||  
                    args.get_eventTarget().indexOf("ExportToPdfButton") >= 0 ||  
                    args.get_eventTarget().indexOf("ExportToCsvButton") >= 0) {  
 
                         args.set_enableAjax(false);  
                     }  
                 }  
        </script> 
    </telerik:RadCodeBlock> 
    <div> 
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">  
            <ClientEvents  OnRequestStart="onRequestStart" /> 
        </telerik:RadAjaxManager> 
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Default">  
        </telerik:RadAjaxLoadingPanel> 
     
 
    <div align=center>  
        <asp:Label ID="Label1" runat="server"   
            Text="Qwest Tele Sales Crossmedia Report Tool" Font-Bold="True"   
            Font-Italic="True" Font-Size="XX-Large"></asp:Label> 
            </> 
    </div> 
     
        <telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticUpdates="True" 
            AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True" DataSourceID="SqlDataSource1" 
            GridLines="None" EnableLinqExpressions="False"   
            OnItemCommand="RadGrid1_ItemCommand"   
            onexcelmlexportrowcreated="RadGrid1_ExcelMLExportRowCreated"   
            onexcelmlexportstylescreated="RadGrid1_ExcelMLExportStylesCreated"   
            onitemcreated="RadGrid1_ItemCreated">  
            <MasterTableView AutoGenerateColumns="False" DataKeyNames="ID" 
                DataSourceID="SqlDataSource1" EditMode="PopUp">  
                <RowIndicatorColumn> 
                    <HeaderStyle Width="20px"></HeaderStyle> 
                </RowIndicatorColumn> 
                <ExpandCollapseColumn> 
                    <HeaderStyle Width="20px"></HeaderStyle> 
                </ExpandCollapseColumn> 
                <Columns> 
                    <telerik:GridEditCommandColumn> 
                    </telerik:GridEditCommandColumn> 
                    <telerik:GridBoundColumn DataField="ID" DataType="System.Int64" HeaderText="ID" ReadOnly="True" 
                        SortExpression="ID" UniqueName="ID" HeaderStyle-Width="110px">  
                        <FilterTemplate> 
                        Clear filters  
                        <asp:ImageButton ID="btnShowAll" runat="server" ImageUrl="Img/filterCancel.gif" OnClick="btnShowAll_Click" 
                                Style="vertical-align: middle" /> 
                        </FilterTemplate> 
 
<HeaderStyle Width="110px"></HeaderStyle> 
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="SID" DataType="System.Int64" HeaderText="SID" ReadOnly="true" ForceExtractValue="InEditMode" 
                        SortExpression="SID" UniqueName="SID">  
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="Username" HeaderText="Username" SortExpression="Username" ReadOnly="true" ForceExtractValue="InEditMode" 
                        UniqueName="Username">  
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="First" HeaderText="First" SortExpression="First" ReadOnly="true" ForceExtractValue="InEditMode" 
                        UniqueName="First">  
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="Last" HeaderText="Last" SortExpression="Last" ReadOnly="true" ForceExtractValue="InEditMode" 
                        UniqueName="Last">  
                    </telerik:GridBoundColumn> 
                    <telerik:GridCheckBoxColumn DataField="EngPostcard" DataType="System.Boolean" HeaderText="EngPostcard" 
                        SortExpression="EngPostcard" UniqueName="EngPostcard">  
                    </telerik:GridCheckBoxColumn> 
                    <telerik:GridCheckBoxColumn DataField="EngEmail" DataType="System.Boolean" HeaderText="EngEmail" 
                        SortExpression="EngEmail" UniqueName="EngEmail">  
                    </telerik:GridCheckBoxColumn> 
                    <telerik:GridBoundColumn DataField="Name" HeaderText="Name" SortExpression="Name" 
                        UniqueName="Name">  
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="Speed" HeaderText="Speed" SortExpression="Speed" 
                        UniqueName="Speed">  
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="Email" HeaderText="Email" SortExpression="Email" 
                        UniqueName="Email">  
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="Address1" HeaderText="Address1" SortExpression="Address1" 
                        UniqueName="Address1">  
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="Address2" HeaderText="Address2" SortExpression="Address2" 
                        UniqueName="Address2">  
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="City" HeaderText="City" SortExpression="City" 
                        UniqueName="City">  
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="State" HeaderText="State" SortExpression="State" 
                        UniqueName="State">  
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="Zip" HeaderText="Zip" SortExpression="Zip" UniqueName="Zip">  
                    </telerik:GridBoundColumn> 
                    <telerik:GridDateTimeColumn DataField="DateVisited" DataType="System.DateTime" HeaderText="DateVisited" 
                        SortExpression="DateVisited" UniqueName="DateVisited">  
                    </telerik:GridDateTimeColumn> 
                   <telerik:GridBoundColumn DataField="DateRegistered" DataType="System.DateTime" HeaderText="DateRegistered" 
                        SortExpression="DateRegistered"  UniqueName="DateRegistered" > 
                        <FilterTemplate> 
                            From  
                            <telerik:RadDatePicker ID="FromDateRegisteredPicker" runat="server" Width="85px" 
                                ClientEvents-OnDateSelected="FromDateRegisteredSelected" MinDate="06-01-2010" 
                                MaxDate="01-01-2020" FocusedDate="07-04-2010" DbSelectedDate='<%# startDate %>' /> 
                            to  
                            <telerik:RadDatePicker ID="ToDateRegisteredPicker" runat="server" Width="85px" ClientEvents-OnDateSelected="ToDateRegisteredSelected" 
                                MinDate="06-01-2010" MaxDate="01-01-2020" FocusedDate="08-08-2010" DbSelectedDate='<%# endDate %>' /> 
                            <telerik:RadScriptBlock runat="server" ID="RadScriptBlock1">  
 
                                <script type="text/javascript">  
                                    function FromDateRegisteredSelected(sender, args) {  
                                        var tableView = $find("<%#((GridItem)Container).OwnerTableView.ClientID %>");  
                                        var ToDateRegisteredPicker = $find('<%#((GridItem)Container).FindControl("ToDateRegisteredPicker").ClientID %>');  
 
                                        var fromDateRegistered = FormatSelectedDate(sender);  
                                        var toDateRegistered = FormatSelectedDate(ToDateRegisteredPicker);  
 
                                        tableView.filter("DateRegistered", fromDateRegistered + " " + toDateRegistered, "Between");  
                                    }  
 
                                    function ToDateRegisteredSelected(sender, args) {  
                                        var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");  
                                        var fromDateRegisteredPicker = $find('<%# ((GridItem)Container).FindControl("FromDateRegisteredPicker").ClientID %>');  
 
                                        var fromDateRegistered = FormatSelectedDate(fromDateRegisteredPicker);  
                                        var toDateRegistered = FormatSelectedDate(sender);  
                                        tableView.filter("DateRegistered", fromDateRegistered + " " + toDateRegistered, "Between");  
                                    }  
 
                                    function FormatSelectedDate(picker) {  
                                        var date = picker.get_selectedDate();  
                                        var dateInput = picker.get_dateInput();  
                                        var formattedDate = dateInput.get_dateFormatInfo().FormatDate(date, dateInput.get_displayDateFormat());  
 
                                        return formattedDate;  
                                    }  
                                </script> 
 
                            </telerik:RadScriptBlock> 
                        </FilterTemplate> 
                          
                    </telerik:GridBoundColumn> 
                    <telerik:GridCheckBoxColumn DataField="Optout" DataType="System.Boolean" HeaderText="Optout" 
                        SortExpression="Optout" UniqueName="Optout">  
                    </telerik:GridCheckBoxColumn> 
                </Columns> 
 
                <EditFormSettings> 
                <EditColumn UniqueName="EditCommandColumn1"></EditColumn> 
                </EditFormSettings> 
 
            </MasterTableView>          
            <ClientSettings> 
                <ClientEvents OnRowDblClick="RowDblClick" /> 
            </ClientSettings> 
        </telerik:RadGrid> 
    </div> 
            <div class="module" style="height: 110px; width: 92%">  
            <asp:CheckBox ID="CheckBox1" Text="Export only data" runat="server"></asp:CheckBox> 
            <br /> 
            <asp:CheckBox ID="CheckBox2" Text="Ignore paging (exports all pages)" runat="server"></asp:CheckBox> 
            <br /> 
            <asp:CheckBox ID="CheckBox3" Text="Open exported data in new browser window" runat="server"></asp:CheckBox> 
            <br /> 
            <br /> 
            <asp:Button ID="Button1"  Width="150px" Text="Export to Excel" OnClick="Button1_Click" 
            runat="server"></asp:Button> 
            <asp:Button ID="Button4"  Width="150px" Text="Export to ExcelML" OnClick="Button4_Click" 
            runat="server"></asp:Button> 
            <asp:Button ID="Button2"  Width="150px" Text="Export to Word" OnClick="Button2_Click" 
            runat="server"></asp:Button> 
            <asp:Button ID="Button3"  Width="150px" Text="Export to CSV" OnClick="Button3_Click" 
            runat="server"></asp:Button> 
        </div> 
        <br /> 
    </form> 

8 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 07 Jul 2010, 09:40 PM
Hello Amy,

Please set ExportOnlyData="false" and let me know whether the problem still persists.

Regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Amy Liu
Top achievements
Rank 1
answered on 08 Jul 2010, 10:35 PM
  <telerik:GridBoundColumn DataField="Speed" HeaderText="Speed" 
            SortExpression="Speed" UniqueName="Speed">
        </telerik:GridBoundColumn>
  
-----------------------------
  
        <telerik:GridTemplateColumn ColumnEditorID="GridDropDownColumnEditor1" 
            DataField="Speed" HeaderText="Speed" SortExpression="Speed" UniqueName="Speed">
            <EditItemTemplate>
                <telerik:RadComboBox ID="SpeedRadComboBox" runat="server" 
                    DataSourceID="SqlDataSource3" DataTextField="Speed" DataValueField="Speed" 
                    SelectedValue='<%# Bind("Speed") %>'>
                </telerik:RadComboBox>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="SpeedLabel" runat="server" Text='<%# Eval("Speed") %>'></asp:Label>
            </ItemTemplate>
        </telerik:GridTemplateColumn>

1.It didn't export checkbox value for me to csv no matter whether the export data only is checked or not.

2.Another thing is that I used the filter in dataregistered header to filter by date range (two calendars inside), then edit form will not show calender beside the field. ( Usually I can make the column as GridDateTimeColumn in order to show calendar on both-filter and edit form if I don't use filter with date range as datevisited field did.)  If I change the column back to GridDateTimeColumn then the filter's two calendars disappered. so how can I do to show two calendars in filter and one calendar beside the field in edit form?

I am too new for telerik control. please help. thanks.

 

 

 

 

 

 

0
Amy Liu
Top achievements
Rank 1
answered on 09 Jul 2010, 03:21 PM
number 2 issue has been solved by using the column template.
0
Amy Liu
Top achievements
Rank 1
answered on 12 Jul 2010, 10:42 PM
1.It didn't export checkbox value for me to csv no matter whether the export data only is checked or not.

Can anybody solve the simple problem for me?
0
Daniel
Telerik team
answered on 14 Jul 2010, 03:09 PM
Hello Amy,

I attached a runnable demo that shows how to export the CheckBox when ExportOnlyData="false".

Let me know if you need further assistance.

Regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Amy Liu
Top achievements
Rank 1
answered on 15 Jul 2010, 04:13 PM
hrh. i forget to tell you that I am using  Telerik.UI.dll released for asp.net ajax Q2 2009 NET 35.
it don't have

<

 

CommandItemSettings ShowExportToCsvButton="true" /> attribute which will have compile error in my project.

I used your code and added a button on it and run it and still give me nothing.
Below is the aspx and code behind code:

<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  
<head id="Head1" runat="server">
    <title></title>
</head>
<body class="BODY">
    <form runat="server" id="mainForm" method="post">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server" />
    <telerik:RadGrid ID="RadGrid1" runat="server" GridLines="None" AllowPaging="true"
        Width="500px" OnNeedDataSource="RadGrid1_NeedDataSource">
        <ExportSettings ExportOnlyData="false" IgnorePaging="true" OpenInNewWindow="true" />
        <MasterTableView CommandItemDisplay="Top" AutoGenerateColumns="false">
            <CommandItemSettings />
            <Columns>
                <telerik:GridTemplateColumn HeaderText="TemplateColumnCheckBox">
                    <ItemTemplate>
                        <asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Eval("Available") %>' />
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridCheckBoxColumn DataField="Available" HeaderText="CheckBoxColumn" />
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
    </form>
</body>
</html>
  
    protected void Button1_Click(object sender, EventArgs e)
    {
        //export to csv
        RadGrid1.ExportSettings.ExportOnlyData = false;
        RadGrid1.ExportSettings.IgnorePaging = true;
        RadGrid1.ExportSettings.OpenInNewWindow = true;
        RadGrid1.MasterTableView.ExportToCSV(); 
    }
    protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
        System.Data.DataTable table = new System.Data.DataTable();
        table.Columns.Add("Available", typeof(bool));
        for (int i = 0; i < 10; i++)
            table.Rows.Add(i % 2 == 0);
        RadGrid1.DataSource = table;
    }
0
Daniel
Telerik team
answered on 21 Jul 2010, 09:42 AM
Hello Amy,

This won't work with versions of RadControls prior to Q3 2009 SP2. For older versions you should use the following workaround:
bool isExport = false;
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem && isExport)
    {
        TableCell cell = (e.Item as GridDataItem)["TemplateColumnCheckBox"];
        CheckBox chk = cell.FindControl("CheckBox1") as CheckBox;
        cell.Text = chk.Checked.ToString();
    }
}

<telerik:GridTemplateColumn HeaderText="TemplateColumnCheckBox" UniqueName="TemplateColumnCheckBox">
    <ItemTemplate>
        <asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Eval("Available") %>' />
    </ItemTemplate>
</telerik:GridTemplateColumn>

Regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Raj
Top achievements
Rank 1
answered on 25 Nov 2010, 10:33 AM
Hi ,

I am having the same problem. When i export data to excel , its not loading anything for the check box values.

I have a large number of checkBoxes so i used autogenerateColoumns to generate coloumns.

How to solve this issues for the auto generated checkboxes.

Please help me

Thank you
Tags
Grid
Asked by
Amy Liu
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Amy Liu
Top achievements
Rank 1
Raj
Top achievements
Rank 1
Share this question
or