This is a migrated thread and some comments may be shown as answers.
Export grid in Asp Update Panel
5 Answers 66 Views
This is a migrated thread and some comments may be shown as answers.
David Gunderson
Top achievements
Rank 1
David Gunderson asked on 02 Jun 2011, 02:37 PM

Ok looked at some of the code examples but have not found any like mine, and I am wondering if the way i am doing this works somehow in the update panels.  I would hope that this would be built in or easy to change to get the grid to export to PDF, EXCEL or word.

 <asp:UpdatePanel ID="UDP1" runat="server">
        <ContentTemplate>
            <table width="100%">
                <tr>
                    <td align="center"><asp:DropDownList ID="ddlSRpEvent" runat="server" AutoPostBack="true" Width="220px"></asp:DropDownList>&nbsp;&nbsp&nbsp;
                                        <asp:DropDownList ID="ddlSrpDay" runat="server" Width="220px" AutoPostBack="true"></asp:DropDownList></td>
                </tr>
                <tr>
                    <td align="center"><asp:LinkButton ID="lnkReport" runat="server">View Report</asp:LinkButton></td>
                </tr>
                <tr>
                    <td style="height:20px"></td>
                </tr>
            </table>
            <table width="100%">
                <tr>
                    <td align="center">
                        <telerik:RadGrid ID="myRadGrid" runat="server" Width="95%" BorderWidth="1px" CellPadding="6" GridLines="Horizontal" BorderColor="#404040" Skin="Web20" ExportSettings-Excel-Format="Html"
                        ExportSettings-ExportOnlyData="true" ExportSettings-OpenInNewWindow="true"
                        ExportSettings-Pdf-AllowPrinting="true"><ExportSettings><Pdf FontType="Subset" PaperSize="Letter" PageTitle="No Show Report" /><Excel Format="html" FileExtension="NoShow.xlxs" /></ExportSettings>
                        <MasterTableView AutoGenerateColumns="false" HierarchyDefaultExpanded="false" HierarchyLoadMode="ServerBind" BorderColor="#404040" Font-Size="10" Font-Names="Veranda,arial,sans-serif"
                        HeaderStyle-HorizontalAlign="Center" GridLines="Horizontal" CommandItemSettings-ShowExportToPdfButton="true" CommandItemDisplay="Top" CommandItemSettings-ShowExportToExcelButton="true"
                        CommandItemSettings-ShowAddNewRecordButton="false" CommandItemSettings-ShowRefreshButton="false" CommandItemSettings-ShowExportToWordButton="true">
                        <AlternatingItemStyle BackColor="#B0C4DE" />
                        <HeaderStyle ForeColor="White" Font-Bold="true" BorderColor="#404040" BorderWidth="1px" />
                            <Columns>
                                <telerik:GridBoundColumn HeaderText="UIC" DataField="UIC"></telerik:GridBoundColumn>
                                <telerik:GridBoundColumn HeaderText="Att UIC" DataField="AUIC"></telerik:GridBoundColumn>
                                <telerik:GridBoundColumn HeaderText="Rank" DataField="strRank"></telerik:GridBoundColumn>
                                <telerik:GridBoundColumn HeaderText="Name" DataField="strFullName"></telerik:GridBoundColumn>
                                <telerik:GridBoundColumn HeaderText="SRPType" DataField="strShortText"></telerik:GridBoundColumn>
                                <telerik:GridBoundColumn HeaderText="Date" DataField="dtEventDate"></telerik:GridBoundColumn>
                                <telerik:GridBoundColumn HeaderText="Time" DataField="StartTime"></telerik:GridBoundColumn>
                                <telerik:GridBoundColumn HeaderText="Previous SRP" DataField="Srp"></telerik:GridBoundColumn>
                            </Columns>
                         </MasterTableView>
                        </telerik:RadGrid>
                    </td>
                </tr>
            </table>
        </ContentTemplate>
    </asp:UpdatePanel>

 Protected Sub lnkReport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkReport.Click
        FillGrid()
    End Sub

Private Sub FillGrid()
        Dim eventId As String = ddlSRpEvent.SelectedValue
        Dim SqlWhere As String = ""

        If eventId > "0" AndAlso ddlSRpEvent.SelectedValue > "0" Then
            SqlWhere = " intEventid = " & eventId & " and intEventDateId = " & ddlSrpDay.SelectedValue & " "
        Else
            SqlWhere = " intEventid = " & eventId & " "
        End If

        SQL = "Sql statment to fill grid"  Not Shown"

         Dim MyDataTable As DataTable = getData(sql)
        Dim MyNewDataTable As New DataTable
        MyNewDataTable = MyDataTable.Clone()

        Dim theCount As Integer = 0
        Dim totalCount As Integer = 0
        Dim dtnewRow As DataRow
        Dim Unit As String = String.Empty

        totalCount = MyDataTable.Rows.Count

        For Each row As DataRow In MyDataTable.Rows
            If Unit = String.Empty Then
                'First Record, just add it.
                Unit = row("UIC")
                MyNewDataTable.ImportRow(row)
                theCount = theCount + 1
            Else
                If Unit = row("UIC") Then
                    row("UIC") = ""
                    MyNewDataTable.ImportRow(row)
                    theCount = theCount + 1
                Else
                    'row is of different UIC, create a row for totals
                    dtnewRow = MyNewDataTable.NewRow()
                    dtnewRow.Item("SRP") = "TOTAL " & theCount
                    MyNewDataTable.Rows.Add(dtnewRow)
                    theCount = 0
                    'add the row with diffent UIC as well
                    Unit = row("UIC")
                    MyNewDataTable.ImportRow(row)
                    theCount = theCount + 1
                End If
            End If
        Next

        'Add the Footer row with the the total count
        dtnewRow = MyNewDataTable.NewRow()
        dtnewRow.Item("SRP") = "TOTAL ALL UIC's " & totalCount
        MyNewDataTable.Rows.Add(dtnewRow)

        myRadGrid.DataSource = MyNewDataTable
        myRadGrid.DataBind()

    End Sub

5 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 07 Jun 2011, 09:55 AM
Hello David,

You need to register the export buttons as postback controls. To do that, you need to find the buttons in the command item and use the ScriptManager.RegisterPostBackControl() method. You can use the ItemCreated event in RadGrid to find the command item:

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridCommandItem)
    {
        var excel = e.Item.FindControl("ExportToExcelButton");
        if (excel != null)
            ScriptManager1.RegisterPostBackControl(excel);
 
        var word = e.Item.FindControl("ExportToWordButton");
        if (word != null)
            ScriptManager1.RegisterPostBackControl(word);
 
        var pdf = e.Item.FindControl("ExportToPdfButton");
        if (pdf != null)
            ScriptManager1.RegisterPostBackControl(pdf);
 
        var csv = e.Item.FindControl("ExportToCsvButton");
        if (csv != null)
            ScriptManager1.RegisterPostBackControl(csv);
    }
}

Now your export buttons will make full postbacks and you will be able to export from inside the UpdatePanel.

Veli
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
JJ
Top achievements
Rank 1
answered on 04 Aug 2011, 07:21 PM
I have radupload inside radgrid as GridTemplateColumn/ItemTemplate

I used the following:

 

 

if (e.Item is GridDataItem)

 

{

 

RadUpload upload = (RadUpload)e.Item.FindControl("myradupload");  

 

RadScriptManager sm = (RadScriptManager)Page.Master.FindControl("ScriptManager1");

 

sm.RegisterPostBackControl(upload);

}

 



but radupload still can't get anything, upload.UploadedFiles.Count always=0 no matter what if I have update panel ouside the radgrid.

RegisterPostBackControl doesn't seem work for me
0
Veli
Telerik team
answered on 08 Aug 2011, 04:25 PM
Hello Jj,

In your case, you should not register the RadUpload instance as a PostBack control, but the button (or actual control) that is posting the page once you select a file for upload. For example, if you select a file for upload and click a button (e.g. Save, or Upload), the button is the actual posting control, not the upload. In your case, you need to find the control that will be clicked (or will trigger a postback) once a file is selected with RadUpload.

Greetings,
Veli
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Asutosh
Top achievements
Rank 1
answered on 05 Jul 2014, 12:26 PM
hi
i am using rad grid with hierarchy
and also i export it as excel and pdf
now problem is that i want to export it as asynchronously so how can i achieve that functionality?
0
Princy
Top achievements
Rank 1
answered on 07 Jul 2014, 04:32 AM
Hi Asutosh,

The exporting feature works only with regular postbacks. This means, that the asynchronous postback should be canceled when performing an export. More information on this topic is available below:
Export from Ajaxified Grid
Exclude Controls from Ajaxifying
Export RadGrid content to Excel/Word/CSV/PDF with Ajax enabled

Thanks,
Princy
Tags
Grid
Asked by
David Gunderson
Top achievements
Rank 1
Answers by
Veli
Telerik team
JJ
Top achievements
Rank 1
Asutosh
Top achievements
Rank 1
Princy
Top achievements
Rank 1
Share this question
or