Export grid in Asp Update Panel

6 posts, 0 answers
  1. David Gunderson
    David Gunderson avatar
    13 posts
    Member since:
    Apr 2010

    Posted 02 Jun 2011 Link to this post

    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

  2. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 07 Jun 2011 Link to this post

    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.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. JJ
    JJ avatar
    147 posts
    Member since:
    May 2010

    Posted 04 Aug 2011 Link to this post

    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
  5. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 08 Aug 2011 Link to this post

    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.

  6. Asutosh
    Asutosh avatar
    130 posts
    Member since:
    Sep 2013

    Posted 05 Jul 2014 in reply to Veli Link to this post

    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?
  7. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 06 Jul 2014 in reply to Asutosh Link to this post

    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017