Problem: How to display more columns in a Telerik grid than are displayed in the rendered grid?
eg I'd like to only display on the screen the Surname, but on dump to csv would like firstname too.
I've tried visible = false, and display = false on the GridBoundColumns, but then they don't come out on the csv.
<telerik:RadGrid ID="grdAuctions" runat="server" AllowAutomaticDeletes="True" AllowAutomaticUpdates="True"
AllowPaging="False" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="odsAuctionSales"
GridLines="None" EnableEmbeddedSkins="False" OnItemDataBound="grdAuctionSales_ItemDataBound">
<ExportSettings HideStructureColumns="true" />
<MasterTableView Width="100%" CommandItemDisplay="Top">
<PagerStyle Mode="NextPrevNumericAndAdvanced" />
<CommandItemSettings ShowAddNewRecordButton="false" ShowRefreshButton="false" ShowExportToCsvButton="true"
ExportToCsvImageUrl="~/Images/excel.jpg" ExportToCsvText="Export to csv" />
</MasterTableView>
<MasterTableView DataKeyNames="Id" DataSourceID="odsAuctionSales" CssClass="listItems"
Width="98%">
<SortExpressions>
<telerik:GridSortExpression FieldName="Name"></telerik:GridSortExpression>
</SortExpressions>
<RowIndicatorColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<ExpandCollapseColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<Columns>
<telerik:GridTemplateColumn UniqueName="Edit">
<ItemTemplate>
<asp:HyperLink ID="edit" runat="server" Text="Edit"></asp:HyperLink>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="NameOnTable" HeaderText="Name On Table" SortExpression="NameOnTable"
UniqueName="NameOnTable">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Surname" HeaderText="Surname" SortExpression="Surname"
UniqueName="Surname">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Firstname" HeaderText="Firstname" SortExpression="Firstname"
UniqueName="Firstname">
</telerik:GridBoundColumn>
Edit Here is how I got it working
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.ExportToCsvCommandName)
{
grdAuctions.MasterTableView.GetColumn("Edit").Visible = false;
grdAuctions.MasterTableView.GetColumn("DPSAuthCode").Visible = true;
grdAuctions.MasterTableView.ExportToCSV();
}
}
and in the aspx
OnItemCommand="RadGrid1_ItemCommand"
and
<telerik:GridBoundColumn DataField="DPSAuthCode" HeaderText="DPSAuthCode" Visible="false"
SortExpression="DPSAuthCode" UniqueName="DPSAuthCode">
</telerik:GridBoundColumn>
Switching the Visible or Display property value prior to the export call should do the trick. Check the relevant section (Hide Columns) here for details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With