The problem which i am facing is that i have an ExportToExcel image button in the grid.When i click on that , it is not asking for 'Open' or 'Save' file in Excel. Instead the datas which are to be in the Excel is displayed in UI grid itself. The excel button is in the "GridFilteringItem" . Please note that the grid is placed within RadAjaxPanel.The code which I have used is
public void grid _ItemCreated(object sender, GridItemEventArgs e)
{
//if (e.Item is GridCommandItem)
//{
// Button btncmd = (e.Item as GridCommandItem).FindControl("ExportToExcelButton") as Button;
// (this.Master.FindControl("ScriptManagerMain") as System.Web.UI.ScriptManager).RegisterPostBackControl(btncmd);
//}
if (e.Item is GridHeaderItem)
{
GridHeaderItem headerItem = (GridHeaderItem)e.Item; // access the header row
Button btnUpdate = new Button(); // creating a new checkbox
btnUpdate.ID = "btnUpdate";
btnUpdate.Text = "Update Selected";
btnUpdate.OnClientClick = "ValidateCheckBox()";
btnUpdate.Click += new EventHandler(btnUpdateSelected_Click);
headerItem["Update"].Controls.Add(btnUpdate); // adding the checkbox to the control collection of the required cell
btnUpdate.Visible = true;
}
if (e.Item is GridFilteringItem)
{
ImageButton ExportToXLSButton = new ImageButton();
ExportToXLSButton.ID = "CustomExportToExcelButton";
ExportToXLSButton.AlternateText = ExportToXLSButton.ToolTip = "Export To Excel";
ExportToXLSButton.ImageUrl = "~/images/ExportToExcel.gif";
ExportToXLSButton.CommandName = RadGrid.ExportToExcelCommandName;
(e.Item as GridFilteringItem)["Update"].Controls.Add(ExportToXLSButton);
}
}
In ItemCommand
if (e.CommandName == RadGrid.ExportToExcelCommandName)
{
grid.ExportSettings.FileName = String.Format("X_{0}_to_{1}",
dtStart.SelectedDate.Value.ToString("MM-dd-yyyy"), dtEnd.SelectedDate.Value.ToString("MM-dd-yyyy"));
{
if (col.UniqueName != "X")
{
col.Visible = true;
}
}
grid.ExportSettings.ExportOnlyData = true;
grid.ExportSettings.IgnorePaging = true;
grid.ExportSettings.OpenInNewWindow = true;
grid.Rebind();
grid.MasterTableView.ExportToExcel();
I had even referred to the below links but i could not find any solution for this
http://www.telerik.com/forums/radgrid-export-to-excel-problem
http://www.telerik.com/help/aspnet-ajax/grid-export-with-ajax-enabled.html
http://www.telerik.com/help/aspnet-ajax/ajax-exclude
Please help me out on this issue
Thanks
public void grid _ItemCreated(object sender, GridItemEventArgs e)
{
//if (e.Item is GridCommandItem)
//{
// Button btncmd = (e.Item as GridCommandItem).FindControl("ExportToExcelButton") as Button;
// (this.Master.FindControl("ScriptManagerMain") as System.Web.UI.ScriptManager).RegisterPostBackControl(btncmd);
//}
if (e.Item is GridHeaderItem)
{
GridHeaderItem headerItem = (GridHeaderItem)e.Item; // access the header row
Button btnUpdate = new Button(); // creating a new checkbox
btnUpdate.ID = "btnUpdate";
btnUpdate.Text = "Update Selected";
btnUpdate.OnClientClick = "ValidateCheckBox()";
btnUpdate.Click += new EventHandler(btnUpdateSelected_Click);
headerItem["Update"].Controls.Add(btnUpdate); // adding the checkbox to the control collection of the required cell
btnUpdate.Visible = true;
}
if (e.Item is GridFilteringItem)
{
ImageButton ExportToXLSButton = new ImageButton();
ExportToXLSButton.ID = "CustomExportToExcelButton";
ExportToXLSButton.AlternateText = ExportToXLSButton.ToolTip = "Export To Excel";
ExportToXLSButton.ImageUrl = "~/images/ExportToExcel.gif";
ExportToXLSButton.CommandName = RadGrid.ExportToExcelCommandName;
(e.Item as GridFilteringItem)["Update"].Controls.Add(ExportToXLSButton);
}
}
In ItemCommand
if (e.CommandName == RadGrid.ExportToExcelCommandName)
{
grid.ExportSettings.FileName = String.Format("X_{0}_to_{1}",
dtStart.SelectedDate.Value.ToString("MM-dd-yyyy"), dtEnd.SelectedDate.Value.ToString("MM-dd-yyyy"));
{
if (col.UniqueName != "X")
{
col.Visible = true;
}
}
grid.ExportSettings.ExportOnlyData = true;
grid.ExportSettings.IgnorePaging = true;
grid.ExportSettings.OpenInNewWindow = true;
grid.Rebind();
grid.MasterTableView.ExportToExcel();
I had even referred to the below links but i could not find any solution for this
http://www.telerik.com/forums/radgrid-export-to-excel-problem
http://www.telerik.com/help/aspnet-ajax/grid-export-with-ajax-enabled.html
http://www.telerik.com/help/aspnet-ajax/ajax-exclude
Please help me out on this issue
Thanks