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

[Solved] RadGrid Data Export to Excel

3 Answers 132 Views
Grid
This is a migrated thread and some comments may be shown as answers.
anvesh amaravadi
Top achievements
Rank 1
anvesh amaravadi asked on 19 Nov 2009, 11:27 PM
Hey I have used a radgrid and i have tried to export the data  to excel using the code below
but the thing happened after clicking the button is that it doesn't took me to any excel spread sheet but has changed the format of data like and excel sheet on the same page

what should i do to get the data into excel document here is the code 

protected

 

void Button5_Click(object sender, EventArgs e)

 

{

radgrid1.ExportSettings.ExportOnlyData =

true;

 

radgrid1.ExportSettings.IgnorePaging =

true;

 

radgrid1.MasterTableView.AllowFilteringByColumn =

false;

 

radgrid1.ExportSettings.OpenInNewWindow =

true;

 

radgrid1.MasterTableView.ExportToExcel();

 

}

3 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 20 Nov 2009, 04:51 AM
Hello Anvesh,

The exporting feature of the grid does not work when the control is ajaxified but works only with regular postbacks. Hence, I suppose you have enabled ajax for the grid. If so, refer to the following document on exporting from RadGrid with ajax settings:
Export from ajaxified grid

Thanks
Princy.
0
anvesh amaravadi
Top achievements
Rank 1
answered on 20 Nov 2009, 06:23 PM
Princy,

Thanks I have got the Export Working
I appreciate your help
I Have one more question
How can i put Export Excel Button right on top of rad grid i.e. exactly beside the column names of the grid
0
Princy
Top achievements
Rank 2
answered on 23 Nov 2009, 06:03 AM
Hello Anvesh,

You could probably add the imagebutton beside the first column in the column header. Check out the following code snippet in order to achieve the same.

cs:
 
    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridHeaderItem) 
        { 
            GridHeaderItem headerItem = (GridHeaderItem)e.Item; 
            ImageButton btn = new ImageButton(); 
            btn.ImageUrl = "~/Images/ExportImage.gif"
            btn.Click += new ImageClickEventHandler(btn_Click); 
            headerItem["FistColumnUninquName"].Controls.AddAt(0, btn); 
        } 
    } 
    void btn_Click(object sender, ImageClickEventArgs e) 
    { 
        // Code for exporting 
    } 

Could you explain bit more about the scenario, If this is not the exact requirement?

Thanks,
Princy.
Tags
Grid
Asked by
anvesh amaravadi
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
anvesh amaravadi
Top achievements
Rank 1
Share this question
or