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

sharepoint 2010 visual web part and radgrid export

6 Answers 101 Views
WebParts for SharePoint
This is a migrated thread and some comments may be shown as answers.
Myat
Top achievements
Rank 1
Myat asked on 20 Oct 2011, 11:27 PM
export to excel,pdf,csv are not working.  below is the code sample.

 

 

<asp:UpdatePanel runat="server"><ContentTemplate>
<telerik:RadGrid ID="RadGrid1" runat="server" ShowStatusBar="true" Skin="Outlook"
    AutoGenerateColumns="False" PageSize="12" AllowSorting="True" AllowMultiRowSelection="False"
    AllowPaging="True" OnNeedDataSource="RadGrid1_NeedDataSource" 
    OnItemCommand="RadGrid1_ItemCommand" AllowFilteringByColumn="True">
    <PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>
    <ExportSettings IgnorePaging="true" OpenInNewWindow="true" ExportOnlyData="true"/>
    <ClientSettings>
        <Scrolling AllowScroll="true" UseStaticHeaders="false"/>
        </ClientSettings>
  
    <MasterTableView Width="100%" DataKeyNames="intID" AllowMultiColumnSorting="True" CommandItemDisplay="Top"
        CommandItemSettings-ShowExportToExcelButton="true" CommandItemSettings-ShowAddNewRecordButton="false" UseAllDataFields="true">
    <Columns>
        <telerik:GridEditCommandColumn></telerik:GridEditCommandColumn>
        <telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="column" />
        <telerik:GridBoundColumn SortExpression="strSiteID" HeaderText="Location" HeaderButtonType="LinkButton"
            DataField="strSiteID">
        </telerik:GridBoundColumn>
        <telerik:GridDateTimeColumn  SortExpression="dtInvoiceDate" HeaderText="Invoice Date" HeaderButtonType="LinkButton"
            DataField="dtInvoiceDate" DataFormatString="{0:d}" PickerType="DatePicker" FilterControlWidth="100px" >
        </telerik:GridDateTimeColumn>
        <telerik:GridBoundColumn SortExpression="strInvoiceNo" HeaderText="Invoice" HeaderButtonType="LinkButton"
            DataField="strInvoiceNo">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn SortExpression="strItemNo" HeaderText="Part #" HeaderButtonType="LinkButton"
            DataField="strItemNo">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn SortExpression="intItemCount" HeaderText="QTY" HeaderButtonType="LinkButton"
            DataField="intItemCount">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn SortExpression="strCondition" HeaderText="Condition" HeaderButtonType="LinkButton"
            DataField="strCondition">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn SortExpression="strStatus" HeaderText="Status" HeaderButtonType="LinkButton"
            DataField="strStatus">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn SortExpression="strETA" HeaderText="ETA" HeaderButtonType="LinkButton"
            DataField="strETA">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn SortExpression="strBoxID" HeaderText="Box ID" HeaderButtonType="LinkButton"
            DataField="strBoxID">
        </telerik:GridBoundColumn>
    </Columns>
    </MasterTableView>
</telerik:RadGrid>
</ContentTemplate></asp:UpdatePanel>

disabling ajaxifying didn't help.

 

6 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 25 Oct 2011, 04:40 PM
Hi Myat,

You need the following code in the OnInit event of your web part class:
protected override void OnInit(EventArgs e)
{
    base.OnInit(e);
    Page.ClientScript.RegisterStartupScript(typeof(Web_Part1), this.ID, "_spOriginalFormAction = document.forms[0].action;_spSuppressFormOnSubmitWrapper=true;", true);
    if (this.Page.Form != null)
    {
        string formOnSubmitAtt = this.Page.Form.Attributes["onsubmit"];
        if (!string.IsNullOrEmpty(formOnSubmitAtt) && formOnSubmitAtt == "return _spFormOnSubmitWrapper();")
        {
            this.Page.Form.Attributes["onsubmit"] = "_spFormOnSubmitWrapper();";
        }
    }
}


Hope it helps.

Best wishes, Tsvetoslav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Ronak
Top achievements
Rank 1
answered on 23 Aug 2012, 11:45 AM
Thanks Tsvetoslav.I have two seperate RadGrid controls in UserControl and these two control is used in radTabstrip in visual webpart.everything is ajaxify and working well with your help.Now i want to add Export functionality.
I know i need to first cancel Ajax request but how can i add client events as i am adding Ajaxmanager programaticlly.i got your help from this thread....

Please advise

Thanks
ROnak 
 
0
Maria Ilieva
Telerik team
answered on 28 Aug 2012, 11:27 AM
Hello Ronak,

You could get reference to the main RadAjaxManager control and add handlers for the needed client events like this:

C#:
protected void Page_Load(object sender, EventArgs e)
{
    RadAjaxManager manager = RadAjaxManager.GetCurrent(Page);
    manager.ClientEvents.OnRequestStart = "onRequestStart";
    manager.ClientEvents.OnResponseEnd = "onResponseEnd";
    manager.AjaxRequest += new RadAjaxControl.AjaxRequestDelegate(manager_AjaxRequest);
}
protected void manager_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e)
{
    //handle the manager AjaxRequest event here
}

I hope this helps.

Regards,
Maria Ilieva
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Ronak
Top achievements
Rank 1
answered on 28 Aug 2012, 11:57 AM
Thanks Maria i will try and share knowledge here

Ronak
0
Ronak
Top achievements
Rank 1
answered on 28 Aug 2012, 01:12 PM
Thanks Maria it worked and i can export to PDF,word and excel but everytime i need to refersh page after one export meaning lets say first i exported to PDF now if i want to export to word or excel i have to refersh page.

Thanks 
ROnak
0
Ronak
Top achievements
Rank 1
answered on 28 Aug 2012, 02:08 PM
Thanks Maria it is fixed code provided by Tsvetoslav in this thread.

Ronak
Tags
WebParts for SharePoint
Asked by
Myat
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Ronak
Top achievements
Rank 1
Maria Ilieva
Telerik team
Share this question
or