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

[Solved] Hide DataKeyNames from Export

2 Answers 102 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jon
Top achievements
Rank 1
Jon asked on 21 Sep 2009, 03:18 PM
Hello,

I am using the export feature of RadGrid to export data to our user community in excel format.
I am setting AutoGenerateColumns to true upon export so that the ouput includes data that is not visible in the grid.
This action will cause the DataKeyNames to be included in the export output.
The DataKeyNames of the MasterTableView are of course necessary when binding data to the grid (binding to the grid is required when exporting).
I would like to hide the DataKeyNames from the export since they reference primary keys for the data and shouldn't be exposed to our users.

Since the grid must be bound before the export, how do I exclude the DataKeyNames from the excel output?

Thanks,
Jon

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 22 Sep 2009, 07:00 AM
Hello Jon,

You can hide the DataKeyName field in the grid as shown in the code below:
aspx:
<telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1"  AutoGenerateColumns="true" runat="server" > 
      <MasterTableView DataSourceID="SqlDataSource1" DataKeyNames="CustomerID">                

c#:
protected void btnExport_Click(object sender, EventArgs e) 
    { 
        RadGrid1.MasterTableView.GetColumn("CustomerID").Visible = false; 
        
        RadGrid1.ExportSettings.IgnorePaging = true
        RadGrid1.ExportSettings.OpenInNewWindow = true
        RadGrid1.MasterTableView.ExportToExcel(); 
    } 

Thanks
Shinu.
0
Jon
Top achievements
Rank 1
answered on 22 Sep 2009, 04:26 PM
Shinu,

That did the trick.
Thanks.
Tags
Grid
Asked by
Jon
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Jon
Top achievements
Rank 1
Share this question
or