locked
open multiple pdf RRS feed

  • Question

  • User855106052 posted

    Hello everyone,

    I'm here with an issue. How can I do checking 1 or more checkboxes from a repeater open the corresponding pdf (s)?

    I have the following repeater:

    <table width="100%" border="0" cellpadding="5" cellspacing="0" bgcolor="#FFFFFF" class="TextoNormalEscuro" style="margin-bottom:5px;" id="tbluserdata">  
    <asp:Repeater ID="RptTabelaServicos" runat="server">
        <itemtemplate>
            <tr onClick="IrParaURL('<%# Container.DataItem("ServicoCod") %>')" onMouseOver="this.className='highlight2'" onMouseOut="this.className='normal'">
                <td width="16" style=" border-bottom:#EFEFEF 2px solid;"><asp:CheckBox ID="ChkSelecionaServico" runat="server"></asp:CheckBox></td>
                <td width="75" style=" border-bottom:#EFEFEF 2px solid;"><div style="text-align:center;"><asp:Label ID="LblServicoCodLinha" Text='<%# Container.DataItem("ServicoCod") %>' runat="server" Visible="TRUE"></asp:Label></div></td>
                <td width="75" style=" border-bottom:#EFEFEF 2px solid;"><div align="center"><%#DataBinder.Eval(Container.DataItem, "ServicoData","{0:d}")%></div></td>
                <td class="TextoNormalEscuro" style=" border-bottom:#EFEFEF 2px solid;"><%# Container.DataItem("ServicoDestino") %></td>
                <td width="50" style=" border-bottom:#EFEFEF 2px solid; text-align:center;">
                <asp:LinkButton Id="BtnGeneratePdf" OnClick="btnGeneratePDF_Click" runat="server" CommandArgument='<%# Container.DataItem("ServicoCod") %>' CssClass="BotaoGeral BotaoCinzaPequeno"><i class="fa fa-file-o"></i></asp:LinkButton>
                </td>
            </tr>    
        </itemtemplate>
        </asp:Repeater>
    </table>

    in each line has a button (LinkButton) Id="BtnGeneratePdf" that opens the corresponding pdf:

    	Protected Sub btnGeneratePDF_Click(sender As Object, e As EventArgs)
    		LblServicoSelecionado.Text = DirectCast(sender, LinkButton).CommandArgument
    		Con = New OleDbConnection(StrCon)
    		Dset = New DataSet()
    		Adpt = New OleDbDataAdapter("SELECT * FROM TabServicos WHERE TabServicos.ServicoCod=" & LblServicoSelecionado.Text, Con)
    		Adpt.MissingSchemaAction = MissingSchemaAction.AddWithKey
    		Adpt.Fill(Dset, "TodosOsConteudos")
    		Drw = Dset.Tables("TodosOsConteudos").Rows.Find(LblServicoSelecionado.Text)
    		LblServicoCod.Text = Drw("ServicoCod").Tostring()
    		LblServicoDataCriacao.Text = Drw("ServicoDataCriacao")
    		TbxDestino.Text = Drw("ServicoDestino").Tostring()
    			
    		Dim pdfPath = Path.Combine(Server.MapPath("PDF/tpv_guia.pdf"))
    	
    		' Get the form fields for this PDF and fill them in!
    		Dim formFieldMap = PDFHelper.GetFormFieldNames(pdfPath)
    		formFieldMap("TbxServicoCod") = "Guia n.º " + LblServicoCod.Text
    		formFieldMap("TbxDataCriacao") = LblServicoDataCriacao.Text
    		formFieldMap("TbxDestino") = TbxDestino.Text
    	
    	
    		Dim pdfContents = PDFHelper.GeneratePDF(pdfPath, formFieldMap)
    	
    		PDFHelper.ReturnPDF(pdfContents, "tpv_guia.pdf")
    	End Sub
    

    So far so good.

    now I have a button <asp: button Id = "BtnGenerateSelectedPdfs" runat = "server" onclick = "??????" text = "Open Selected"> </ asp: button> that would have to open all pdfs selected by checkboxes

    how can I do that?

    thanks in advance for all the ideas

    Monday, November 5, 2018 5:24 PM

All replies

  • User475983607 posted

    how can I do that?

    HTTP has one response so you can open one file.   You could zip the files and return the zip.  Or maybe use JavaScript to open multiple windows causing multiple downloads but that might be a bit confusing.  

    Monday, November 5, 2018 5:31 PM
  • User1290358704 posted

    I think it is better to show the user a page with links or download buttons.

    Monday, November 5, 2018 8:53 PM
  • User-893317190 posted

    Hi indesk,

    If your PDFHeloper could return mutiple pdf files , you could get all the checked box to know which line should show the pdf.

    Below is my code.

      <table width="100%" border="0" cellpadding="5" cellspacing="0" bgcolor="#FFFFFF" class="TextoNormalEscuro" style="margin-bottom:5px;" id="tbluserdata">  
    <asp:Repeater ID="RptTabelaServicos" runat="server">
        <itemtemplate>
            <tr >
                <td width="16" style=" border-bottom:#EFEFEF 2px solid;"><asp:CheckBox ID="ChkSelecionaServico" runat="server"></asp:CheckBox></td>
              
                <asp:HiddenField ID="HiddenField1" runat="server"  Value ='<%# Eval("fileId") %>'/>
                <td class="TextoNormalEscuro" style=" border-bottom:#EFEFEF 2px solid;"><%# Eval("fileName") %></td>
                <td width="50" style=" border-bottom:#EFEFEF 2px solid; text-align:center;">
                <asp:LinkButton Id="BtnGeneratePdf"  runat="server" CommandArgument='<%# Eval("fileId") %>' CssClass="BotaoGeral BotaoCinzaPequeno"><i class="fa fa-file-o"></i></asp:LinkButton>
    
                </td>
            </tr>    
        </itemtemplate>
          
        </asp:Repeater>
    </table>
            <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click"  />

    Code behind.

     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If Not IsPostBack Then
    
    
                Dim list As ArrayList = New ArrayList()
                list.Add(New With {.fileName = "fileName1", .fileId = 12})
                list.Add(New With {.fileName = "fileName2", .fileId = 13})
                list.Add(New With {.fileName = "fileName3", .fileId = 14})
                RptTabelaServicos.DataSource = list
                RptTabelaServicos.DataBind()
    
            End If
        End Sub
    
        Protected Sub Button1_Click(sender As Object, e As EventArgs)
            'loop through all the items in the repeater 
            For Each item As RepeaterItem In RptTabelaServicos.Items
                If item.ItemType = ListItemType.Item Or item.ItemType = ListItemType.AlternatingItem Then
                    ' get the checkbox in the item
                    Dim checkBox As CheckBox = CType(item.FindControl("ChkSelecionaServico"), CheckBox)
                    If checkBox.Checked Then
                        Dim hidden As HiddenField = CType(item.FindControl("HiddenField1"), HiddenField)
                        Response.Write("you have selected the file with id :" + hidden.Value + "<br/>")
                    End If
                End If
            Next
    
        End Sub

    The result.

    If your PDFHelper couldn't return multiple pdfs, I think you should look for another library.

    Best regards,

    Ackerly Xu

    Tuesday, November 6, 2018 5:35 AM