+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / How to create the Export tool

How to create the Export tool

12 posts, 0 answered
  1. Jaison
    Jaison avatar
    5 posts
    Registered:
    07 Sep 2010
    07 Sep 2010
    Link to this post
    Hello telrik team
     I am new in sitefinity .Please tell me how to create my Export to Excel under Administration/Tool  in sitefinity , by give step by step description . I need to Export two forms(Newsletter,contactus) data from my table to excel . Its very urgent.

    Thanks in advance
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    07 Sep 2010
    Link to this post
    Hello Jaison,

    You can take a look at this post where I have provided the code you need.

    Greetings,
    Ivan Dimitrov
    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
  3. Jaison
    Jaison avatar
    5 posts
    Registered:
    07 Sep 2010
    07 Sep 2010
    Link to this post
    Thanks Ivan. But please clear one more doubt. How can I add Contactus, Newsletter to the leftside .so that when I click Contactus, inside controlpanel my Export Button come.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    07 Sep 2010
    Link to this post
    Hello Jaison,

    The easiest way to do this is adding a static Linkbutton inside

    Sitefinity\Admin\ControlTemplates\Notifications\CommandPanel.ascx and subscribe for its Click event. Inside the event you can export the users. You can use DataManager class and its methods to get a given subset of users that will be exported.

    Kind regards,
    Ivan Dimitrov
    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
  5. Jaison
    Jaison avatar
    5 posts
    Registered:
    07 Sep 2010
    07 Sep 2010
    Link to this post
    Hello Ivan,

    I used RadGrid, but while loading page i am getting the error:
    Error: Sys.InvalidOperationException: Type Telerik.Web.UI.Orientation has already been registered. The type may be defined multiple times or the script file that defines it may have already been loaded. A possible cause is a change of settings during a partial update.



  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    07 Sep 2010
    Link to this post
    Hello Jaison,

    The type might be defined multiple times or the script file that defines it may have already been loaded. A possible reason is a change of settings during a partial update. Try using RadScriptManager if you use ScriptManager.

    Best wishes,
    Ivan Dimitrov
    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
  7. Jaison
    Jaison avatar
    5 posts
    Registered:
    07 Sep 2010
    08 Sep 2010
    Link to this post
    I am using RadGrid with Registerscriptmanager=false" in my application .Its working fine,but in some other system the same is throwing "Error: Sys.InvalidOperationException: Type Telerik.Web.UI.Orientation has already been registered. The type may be defined multiple times or the script file that defines it may have already been loaded. A possible cause is a change of settings during a partial update."

    In that system when i removed RegisterScriptmanager=false,it worked fine.
    could you please tell me the reason, and also why should we do that.

    Thanks in advance
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    08 Sep 2010
    Link to this post
    Hi Jaison,

    When you remove the script manager from a  page ( which is done on render) the page thinks that your code does not require AJAX. By default AJAX needs to be registered very early in the page life cycle for it to be recognized. RadControls are AJAX controls and they require ScriptManager on  a page.

    Kind regards,
    Ivan Dimitrov
    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
  9. Jaison
    Jaison avatar
    5 posts
    Registered:
    07 Sep 2010
    08 Sep 2010
    Link to this post
    Hi Ivan,

    When i am adding scriptmanager, i am getting error :
    Only one instance of a ScriptManager can be added to the page.

    Please help me to fix this.

    Below is my code:
    <telerik:RadScriptManager ID="outReach" runat="server"></telerik:RadScriptManager>
    <telerik:RadGrid  ID="RGOnline" RegisterWithScriptManager="false" runat="server" AutoGenerateColumns="False" DataSourceID="sqlDS" GridLines="None">
    <HeaderContextMenu EnableAutoScroll="True"></HeaderContextMenu>

    <MasterTableView DataSourceID="sqlDS">
    <RowIndicatorColumn>
    <HeaderStyle Width="20px"></HeaderStyle>
    </RowIndicatorColumn>

    <ExpandCollapseColumn>
    <HeaderStyle Width="20px"></HeaderStyle>
    </ExpandCollapseColumn>
        <Columns>
            
            <telerik:GridBoundColumn DataField="StudentName" HeaderText="Name"
                SortExpression="StudentName" UniqueName="StudentName">
                <HeaderStyle HorizontalAlign="Left" />
                <ItemStyle HorizontalAlign="Left" />
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Gender" HeaderText="Gender"
                SortExpression="Gender" UniqueName="Gender">
                <HeaderStyle HorizontalAlign="Left" />
                <ItemStyle HorizontalAlign="Left" />
            </telerik:GridBoundColumn>
             <telerik:GridBoundColumn DataField="DateOfBirth" HeaderText="Date Of Birth"
                SortExpression="DateOfBirth" UniqueName="DateOfBirth">
                <HeaderStyle HorizontalAlign="Left" />
                <ItemStyle HorizontalAlign="Left" />
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Nationality" HeaderText="Nationality"
                SortExpression="Nationality" UniqueName="Nationality">
                <HeaderStyle HorizontalAlign="Left" />
                <ItemStyle HorizontalAlign="Left" />
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Occupation" HeaderText="Occupation"
                SortExpression="Occupation" UniqueName="Occupation">
                <HeaderStyle HorizontalAlign="Left" />
                <ItemStyle HorizontalAlign="Left" />
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="UploadedFilePath" HeaderText="UploadedFilePath"
                SortExpression="UploadedFilePath" UniqueName="UploadedFilePath">
                <HeaderStyle HorizontalAlign="Left" />
                <ItemStyle HorizontalAlign="Left" />
            </telerik:GridBoundColumn>
             <telerik:GridBoundColumn DataField="Date"
                HeaderText="Register Date" SortExpression="Date"
                UniqueName="Date">
                <HeaderStyle HorizontalAlign="Left" />
                <ItemStyle HorizontalAlign="Left" />
            </telerik:GridBoundColumn>
           
            
        </Columns>
    </MasterTableView>
    </telerik:RadGrid>
    <br />
    <asp:Button ID="btnExport" runat="server" OnClick="btnExport_Click"
        Text="Export OutReach" />
    <br />
    <asp:SqlDataSource ID="sqlDS" runat="server" ConnectionString="<%$ ConnectionStrings:Sitefinity%>"
        SelectCommand="sp_Export" SelectCommandType="StoredProcedure"></asp:SqlDataSource>


    .cs

    private void ExportGridView()
        {
            string attachment = "attachment; filename=Outreach.xls";
            Response.ClearContent();
            Response.AddHeader("content-disposition", attachment);
            Response.ContentType = "application/ms-excel";
            Response.AddHeader("Pragma", "public");

            StringWriter sw = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);

            // Create a form to contain the grid
            HtmlForm frm = new HtmlForm();
            RGOnline.Parent.Controls.Add(frm);
          
            frm.Attributes["runat"] = "server";
            
          
            frm.Controls.Add(RGOnline);

            frm.RenderControl(htw);                   //get error here if i remove RegisterWithScriptManager="false"
        
            Response.Write(sw.ToString());
            Response.End();
        }


    private void PrepareGridViewForExport(Control gv)
        {
            LinkButton lb = new LinkButton();
            Literal l = new Literal();
            string name = String.Empty;
            
            for (int i = 0; i < gv.Controls.Count; i++)
            {
                if (gv.Controls[i].GetType() == typeof(LinkButton))
                {
                    l.Text = (gv.Controls[i] as LinkButton).Text;
                    gv.Controls.Remove(gv.Controls[i]);
                    gv.Controls.AddAt(i, l);
                }
                else if (gv.Controls[i].GetType() == typeof(DropDownList))
                {
                    l.Text = (gv.Controls[i] as DropDownList).SelectedItem.Text;
                    gv.Controls.Remove(gv.Controls[i]);
                    gv.Controls.AddAt(i, l);
                }
                else if (gv.Controls[i].GetType() == typeof(CheckBox))
                {
                    l.Text = (gv.Controls[i] as CheckBox).Checked ? "True" : "False";
                    gv.Controls.Remove(gv.Controls[i]);
                    gv.Controls.AddAt(i, l);
                }
                if (gv.Controls[i].HasControls())
                {
                    PrepareGridViewForExport(gv.Controls[i]);
                }
            }
        }
        protected void btnExport_Click(object sender, EventArgs e)
        {
            PrepareGridViewForExport(RGOnline);
            ExportGridView();
        }
  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    08 Sep 2010
    Link to this post
    Hello Jaison,

    You have already added ScriptManager on the page and this is why you are getting the error. You just do not have to remove scrip reference from the RadGrid control.

    Greetings,
    Ivan Dimitrov
    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
  11. Rashmi
    Rashmi avatar
    1 posts
    Registered:
    20 Jul 2010
    14 Sep 2010
    Link to this post
    Hi,

    I have the same problem.

    I am using a datatable as a datasource for the Rad Grid and then exporting the RadGrid data to excel. On clicking the Export button, I am getting the below error:

    Script control 'RGReg' is not a registered script control. Script controls must be registered using RegisterScriptControl() before calling RegisterScriptDescriptors().
    Parameter name: scriptControl


    I added " RegisterWithScriptManager="False"" to my RadGrid, but with this, I am getting the below error:

    Sys.InvalidOperationException: Type Telerik.Web.UI.Orientation has already been registered. The type may be defined multiple times or the script file that defines it may have already been loaded. A possible cause is a change of settings during a partial update.

    I am also not able to use RadDatepicker and all if I add "RegisterWithScriptManager="False"" to RadGrid.

    Its happening both in IE and Chrome.

    Kindly suggest what needs to be done.

    Regards

  12. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    14 Sep 2010
    Link to this post
    Hi Rashmi,

    The error you are getting is not similar to the error Jaison is getting. Even the error messages have nothing in common but the ScriptManager word. The error you are getting is normally caused if you are overriding an OnLoad or OnInit server side method of the user control or custom control where you have the RadGrid and you are not calling the base method. For example the correct call to OnLoad would be:
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        //add your logic
    }

    Then try removing the RegisterWithScriptManager="False" settings.

    All the best,
    Radoslav Georgiev
    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
Register for webinar
12 posts, 0 answered