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

Two Radgrids on page - Export not working for first grid

4 Answers 57 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Laurie
Top achievements
Rank 2
Laurie asked on 17 Jun 2010, 08:54 PM
I have two radgrids on a page and export is not working on the first grid.  In fact, when you click the export button, that grid's header command and filter rows disappear.  Sorting, filtering, and paging work just fine, but not exporting.  Here's my code:

XML Input File:
<?xml version="1.0" encoding="utf-8" ?> 
<years> 
    <year value="2010" name="rat"></year> 
    <year value="2011" name="cat"></year> 
    <year value="2012" name="moose"></year> 
    <year value="2013" name="deer"></year> 
  <year value="2014" name="tiger"></year> 
  <year value="2015" name="dragon"></year> 
  <year value="2016" name="skunk"></year> 
  <year value="2017" name="armadillo"></year> 
  <year value="2018" name="dog"></year> 
  <year value="2019" name="goldfish"></year> 
  <year value="2020" name="koi"></year> 
  <year value="2021" name="catfish"></year> 
  <year value="2022" name="snake"></year> 
  <year value="2023" name="beaver"></year> 
  <year value="2024" name="dalmation"></year> 
  <year value="2025" name="bluebird"></year> 
  <year value="2026" name="boar"></year> 
  <year value="2027" name="toad"></year> 
  <year value="2028" name="mouse"></year> 
  <year value="2029" name="salamander"></year> 
  <year value="2030" name="alligator"></year> 
</years> 

ASPX Code:
    <form id="form1" runat="server">  
        <div> 
            <asp:ScriptManager runat="server" ID="ScriptManager1">  
            </asp:ScriptManager> 
            <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">  
                <AjaxSettings> 
                    <telerik:AjaxSetting AjaxControlID="rgGrid">  
                        <UpdatedControls> 
                            <telerik:AjaxUpdatedControl ControlID="rgGrid" /> 
                        </UpdatedControls> 
                    </telerik:AjaxSetting> 
                </AjaxSettings> 
            </telerik:RadAjaxManager> 
            <table> 
            <tr> 
            <td> 
            <telerik:RadGrid ID="rgGrid" runat="server" OnNeedDataSource="rgGrid_NeedDataSource" Width="45%" 
                OnItemDataBound="rgGrid_ItemDataBound" OnItemCreated="rgGrid_ItemCreated" AutoGenerateColumns="true">  
                <MasterTableView> 
                    <CommandItemTemplate> 
                        <div style="padding: 5px;" align="right">  
                            <strong>Export:&nbsp;&nbsp;</strong><asp:ImageButton ID="ibExportExcel" runat="server" 
                                ImageUrl="~/images/editorIcons/MSExcell_32.png" ToolTip="Export to Excel" OnClick="ibExportExcel_Click" /> 
                            <asp:ImageButton ID="ibExportWord" runat="server" ImageUrl="~/images/editorIcons/MSWord_32.png" ToolTip="Export to Word"   
                                OnClick="ibExportWord_Click" /></div>  
                    </CommandItemTemplate> 
                </MasterTableView> 
            </telerik:RadGrid> 
            </td><td><telerik:RadGrid ID="rgGrid2" runat="server" OnNeedDataSource="rgGrid2_NeedDataSource" Width="45%" 
                OnItemDataBound="rgGrid2_ItemDataBound" OnItemCreated="rgGrid2_ItemCreated" AutoGenerateColumns="true">  
                <MasterTableView> 
                    <CommandItemTemplate> 
                        <div style="padding: 5px;" align="right">  
                            <strong>Export:&nbsp;&nbsp;</strong><asp:ImageButton ID="ibExportExcel2" runat="server" 
                                ImageUrl="~/images/editorIcons/MSExcell_32.png" ToolTip="Export to Excel" OnClick="ibExportExcel2_Click" /> 
                            <asp:ImageButton ID="ibExportWord2" runat="server" ImageUrl="~/images/editorIcons/MSWord_32.png" ToolTip="Export to Word"   
                                OnClick="ibExportWord2_Click" /></div>  
                    </CommandItemTemplate> 
                </MasterTableView> 
            </telerik:RadGrid> 
            </td></tr></table> 
        </div> 
    </form> 
 

.cs Code:
public partial class WebAdmin_TestGrid_Default : System.Web.UI.Page  
{  
    DataSet ds = new DataSet();  
    bool isForExport = false;  
    bool isForExport2 = false;  
 
    protected void Page_Load(object sender, EventArgs e)  
    {  
        rgGrid.PageSize = Profile.PreferredGridLines;  
        rgGrid2.PageSize = Profile.PreferredGridLines;  
    }
    #region Grid Logic  
 
    protected void rgGrid_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)  
    {  
        ds = new DataSet();  
        string myXMLFile = Server.MapPath("~/App_Data/YearsTest.xml");  
        System.IO.FileStream fsReadXML = new System.IO.FileStream(myXMLFile, System.IO.FileMode.Open);  
        try 
        {  
            ds.ReadXml(fsReadXML);  
        }  
        catch (Exception ex)  
        {  
            Master.SetMessage(ex.ToString());  
        }  
        finally 
        {  
            fsReadXML.Close();  
        }  
        rgGrid.DataSource = ds;  
    }  
    protected void rgGrid_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)  
    {  
        // Hide filter row in export.  
        if (e.Item is GridFilteringItem && isForExport)  
            e.Item.Visible = false;  
 
        // Pull Number of Entries per page in page from web.config appsettings.  
        if (e.Item is GridPagerItem)  
        {  
            GridPagerItem item = e.Item as GridPagerItem;  
            RadComboBox combo = item.FindControl("PageSizeComboBox"as RadComboBox;  
            combo.AutoPostBack = true;  
            combo.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(combo_SelectedIndexChanged);  
        }  
    }  
    protected void rgGrid_ItemDataBound(object sender, GridItemEventArgs e)  
    {  
 
        if (e.Item is GridPagerItem)  
        {  
            GridPagerItem item = e.Item as GridPagerItem;  
 
            RadComboBox combo = item.FindControl("PageSizeComboBox"as RadComboBox;  
            combo.Items.Clear();  
            string strPageSizes = ConfigurationManager.AppSettings["PageSizes"];  
            string[] arrPageSizes = strPageSizes.Split(',');  
            for (int x = 0; x < arrPageSizes.Length; x++)  
            {  
                combo.Items.Add(new RadComboBoxItem(arrPageSizes[x], arrPageSizes[x]));  
            }  
            combo.SelectedValue = rgGrid.MasterTableView.PageSize.ToString();  
        }  
    }  
    void combo_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)  
    {  
        rgGrid.PageSize = int.Parse((o as RadComboBox).SelectedValue);  
        rgGrid.Rebind();  
    }  
    protected void ibExportExcel_Click(object sender, ImageClickEventArgs e)  
    {  
        isForExport = true;  
        rgGrid.MasterTableView.ExportToExcel();  
    }  
    protected void ibExportWord_Click(object sender, ImageClickEventArgs e)  
    {  
        isForExport = true;  
        rgGrid.MasterTableView.ExportToWord();  
    }
    #endregion  
 
    #region Grid2 Logic  
 
    protected void rgGrid2_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)  
    {  
        ds = new DataSet();  
        string myXMLFile = Server.MapPath("~/App_Data/YearsTest.xml");  
        System.IO.FileStream fsReadXML = new System.IO.FileStream(myXMLFile, System.IO.FileMode.Open);  
        try 
        {  
            ds.ReadXml(fsReadXML);  
        }  
        catch (Exception ex)  
        {  
            Master.SetMessage(ex.ToString());  
        }  
        finally 
        {  
            fsReadXML.Close();  
        }  
        rgGrid2.DataSource = ds;  
    }  
    protected void rgGrid2_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)  
    {  
        // Hide filter row in export.  
        if (e.Item is GridFilteringItem && isForExport)  
            e.Item.Visible = false;  
 
        // Pull Number of Entries per page in page from web.config appsettings.  
        if (e.Item is GridPagerItem)  
        {  
            GridPagerItem item = e.Item as GridPagerItem;  
            RadComboBox combo = item.FindControl("PageSizeComboBox"as RadComboBox;  
            combo.AutoPostBack = true;  
            combo.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(combo_SelectedIndexChanged2);  
        }  
    }  
    protected void rgGrid2_ItemDataBound(object sender, GridItemEventArgs e)  
    {  
 
        if (e.Item is GridPagerItem)  
        {  
            GridPagerItem item = e.Item as GridPagerItem;  
 
            RadComboBox combo = item.FindControl("PageSizeComboBox"as RadComboBox;  
            combo.Items.Clear();  
            string strPageSizes = ConfigurationManager.AppSettings["PageSizes"];  
            string[] arrPageSizes = strPageSizes.Split(',');  
            for (int x = 0; x < arrPageSizes.Length; x++)  
            {  
                combo.Items.Add(new RadComboBoxItem(arrPageSizes[x], arrPageSizes[x]));  
            }  
            combo.SelectedValue = rgGrid2.MasterTableView.PageSize.ToString();  
        }  
    }  
    void combo_SelectedIndexChanged2(object o, RadComboBoxSelectedIndexChangedEventArgs e)  
    {  
        rgGrid2.PageSize = int.Parse((o as RadComboBox).SelectedValue);  
        rgGrid2.Rebind();  
    }  
    protected void ibExportExcel2_Click(object sender, ImageClickEventArgs e)  
    {  
        isForExport2 = true;  
        rgGrid2.MasterTableView.ExportToExcel();  
    }  
    protected void ibExportWord2_Click(object sender, ImageClickEventArgs e)  
    {  
        isForExport2 = true;  
        rgGrid2.MasterTableView.ExportToWord();  
    }
    #endregion  
}  
 

4 Answers, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 17 Jun 2010, 09:42 PM
Hello Laurie,

Please examine the following links:
Export from ajaxified grid
Export RadGrid content to Excel/Word/CSV/PDF with Ajax enabled
Exclude controls from ajaxifying

Let me know if the problem still persists after you disable AJAX for the export button.

Best 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
Laurie
Top achievements
Rank 2
answered on 17 Jun 2010, 10:06 PM
Yep.  I removed my RadAjaxManager and it now works.  Thanks!

Laurie
0
Accepted
Daniel
Telerik team
answered on 17 Jun 2010, 10:14 PM
Hello Laurie,

You can still take advantage of AJAX but you have to cancel the request that is initiated by the export button.
<form id="form1" runat="server"
    <div>
        <asp:ScriptManager runat="server" ID="ScriptManager1"
        </asp:ScriptManager>
 
        <script type="text/javascript">
          function onRequestStart(sender, args)
          {
             if (args.get_eventTarget().indexOf("Export") >= 0)
                 args.set_enableAjax(false);
          }
        </script>
 
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" ClientEvents-OnRequestStart="onRequestStart"
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="rgGrid"
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="rgGrid" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>

Best 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
Laurie
Top achievements
Rank 2
answered on 17 Jun 2010, 11:10 PM
Thanks, Daniel.  Works perfectly!
Tags
Grid
Asked by
Laurie
Top achievements
Rank 2
Answers by
Daniel
Telerik team
Laurie
Top achievements
Rank 2
Share this question
or