ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Display PDF inside Ajax Accordion inside ASP.Net Repeater control using C# and VB.Net<p>Hi <a class="username" rel="Amol111"> Amol111</a>,</p> <p>Refer below sample.</p> <p>According to your logic you can use and write your pdf code.</p> <p><span style="text-decoration: underline;"><strong>Database</strong></span></p> <p>For this sample I have used of NorthWind database that you can download using the link given below.</p> <p><a href="https://www.aspsnippets.com/Articles/Install-the-Northwind-and-Pubs-Sample-Databases-in-SQL-Server-Express.aspx" target="_blank">Download Northwind Database</a></p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html">&lt;html xmlns=&#34;http://www.w3.org/1999/xhtml&#34;&gt; &lt;head runat=&#34;server&#34;&gt; &lt;title&gt;&lt;/title&gt; &lt;style type=&#34;text/css&#34;&gt; body { font-family: Arial; font-size: 10pt; } .header_selected { border: 1px solid #FF8C00; color: #FFF; background-color: #FF8C00; font-weight: bold; padding: 5px; margin-top: 5px; cursor: pointer; } .header { border: 1px solid #89BA06; color: #fff; background-color: #89BA06; font-weight: bold; padding: 5px; margin-top: 5px; cursor: pointer; } .header a, .header_selected a { color: #fff; text-decoration: none; } .content { background-color: #F6F6F6; } .content a, .content a:visited { color: #000; margin-left: 20px; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;form id=&#34;form1&#34; runat=&#34;server&#34;&gt; &lt;div&gt; &lt;asp:ScriptManager ID=&#34;ScriptManager1&#34; runat=&#34;server&#34;&gt; &lt;/asp:ScriptManager&gt; &lt;asp:Repeater ID=&#34;rptMenu&#34; runat=&#34;server&#34; OnItemDataBound=&#34;rptMenu_OnItemDataBound&#34;&gt; &lt;ItemTemplate&gt; &lt;asp:HiddenField ID=&#34;hfCountry&#34; Value=&#39;&lt;%# Eval(&#34;Country&#34;) %&gt;&#39; runat=&#34;server&#34; /&gt; &lt;h3&gt; &lt;%#DataBinder.Eval(Container.DataItem, &#34;Country&#34;)%&gt; Employees&lt;/h3&gt; &lt;cc1:Accordion ID=&#34;AccordionMenu&#34; runat=&#34;server&#34; HeaderCssClass=&#34;header&#34; HeaderSelectedCssClass=&#34;header_selected&#34; ContentCssClass=&#34;content&#34; OnItemDataBound=&#34;OnItemDataBound&#34;&gt; &lt;HeaderTemplate&gt; &lt;asp:HyperLink ID=&#34;lnkMenu&#34; Text=&#39;&lt;%# Eval(&#34;Name&#34;) %&gt;&#39; runat=&#34;server&#34; /&gt; &lt;/HeaderTemplate&gt; &lt;ContentTemplate&gt; &lt;asp:HyperLink ID=&#34;HyperLink2&#34; Text=&#39;&lt;%# Eval(&#34;Address&#34;) %&gt;&#39; runat=&#34;server&#34; /&gt; &lt;hr /&gt; &lt;asp:Literal ID=&#34;ltEmbed&#34; runat=&#34;server&#34; /&gt; &lt;/ContentTemplate&gt; &lt;/cc1:Accordion&gt; &lt;br /&gt; &lt;/ItemTemplate&gt; &lt;/asp:Repeater&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt;</pre> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.Data; using AjaxControlToolkit; using System.Configuration; using System.Data.SqlClient;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.Data.SqlClient Imports System.Data Imports AjaxControlToolkit</pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { string constr = ConfigurationManager.ConnectionStrings[&#34;NorthwindConnectionString&#34;].ConnectionString; using (SqlConnection con = new SqlConnection(constr)) { using (SqlCommand cmd = new SqlCommand(&#34;SELECT DISTINCT Country FROM Employees&#34;, con)) { using (SqlDataAdapter da = new SqlDataAdapter(cmd)) { DataTable dt = new DataTable(); da.Fill(dt); rptMenu.DataSource = dt; rptMenu.DataBind(); } } } } } protected void rptMenu_OnItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { HiddenField country = e.Item.FindControl(&#34;hfCountry&#34;) as HiddenField; Accordion accordionMenu = e.Item.FindControl(&#34;AccordionMenu&#34;) as Accordion; SqlDataSource SqlDataSource1 = new SqlDataSource(); SqlDataSource1.ID = &#34;sqlDataSource1&#34;; e.Item.Controls.Add(SqlDataSource1); SqlDataSource1.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings[&#34;NorthwindConnectionString&#34;].ConnectionString; SqlDataSource1.SelectCommand = &#34;SELECT FirstName + &#39; &#39; + LastName Name,Address FROM Employees WHERE Country=&#39;&#34; + country.Value + &#34;&#39;&#34;; accordionMenu.DataSourceID = &#34;SqlDataSource1&#34;; } } protected void OnItemDataBound(object sender, AccordionItemEventArgs e) { if (e.ItemType == AccordionItemType.Content) { AccordionContentPanel cPanel = e.AccordionItem; Literal ltEmbed = (Literal)cPanel.FindControl(&#34;ltEmbed&#34;); string embed = &#34;&lt;object data=\&#34;{0}\&#34; type=\&#34;application/pdf\&#34; width=\&#34;500px\&#34; height=\&#34;200px\&#34;&gt;&#34;; embed += &#34;If you are unable to view file, you can download from &lt;a href = \&#34;{0}\&#34;&gt;here&lt;/a&gt;&#34;; embed += &#34; or download &lt;a target = \&#34;_blank\&#34; href = \&#34;http://get.adobe.com/reader/\&#34;&gt;Adobe PDF Reader&lt;/a&gt; to view the file.&#34;; embed += &#34;&lt;/object&gt;&#34;; ltEmbed.Text = string.Format(embed, ResolveUrl(&#34;~/Files/Test.pdf&#34;)); } }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load If Not Me.IsPostBack Then Dim constr As String = ConfigurationManager.ConnectionStrings(&#34;NorthwindConnectionString&#34;).ConnectionString Using con As SqlConnection = New SqlConnection(constr) Using cmd As SqlCommand = New SqlCommand(&#34;SELECT DISTINCT Country FROM Employees&#34;, con) Using da As SqlDataAdapter = New SqlDataAdapter(cmd) Dim dt As DataTable = New DataTable() da.Fill(dt) rptMenu.DataSource = dt rptMenu.DataBind() End Using End Using End Using End If End Sub Protected Sub rptMenu_OnItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs) If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then Dim country As HiddenField = TryCast(e.Item.FindControl(&#34;hfCountry&#34;), HiddenField) Dim accordionMenu As Accordion = TryCast(e.Item.FindControl(&#34;AccordionMenu&#34;), Accordion) Dim SqlDataSource1 As SqlDataSource = New SqlDataSource() SqlDataSource1.ID = &#34;sqlDataSource1&#34; e.Item.Controls.Add(SqlDataSource1) SqlDataSource1.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings(&#34;NorthwindConnectionString&#34;).ConnectionString SqlDataSource1.SelectCommand = &#34;SELECT FirstName + &#39; &#39; + LastName Name,Notes FROM Employees WHERE Country=&#39;&#34; &amp; country.Value &amp; &#34;&#39;&#34; accordionMenu.DataSourceID = &#34;SqlDataSource1&#34; End If End Sub Protected Sub OnItemDataBound(ByVal sender As Object, ByVal e As AccordionItemEventArgs) If e.ItemType = AccordionItemType.Content Then Dim cPanel As AccordionContentPanel = e.AccordionItem Dim ltEmbed As Literal = CType(cPanel.FindControl(&#34;ltEmbed&#34;), Literal) Dim embed As String = &#34;&lt;object data=&#34;&#34;{0}&#34;&#34; type=&#34;&#34;application/pdf&#34;&#34; width=&#34;&#34;500px&#34;&#34; height=&#34;&#34;200px&#34;&#34;&gt;&#34; embed += &#34;If you are unable to view file, you can download from &lt;a href = &#34;&#34;{0}&#34;&#34;&gt;here&lt;/a&gt;&#34; embed += &#34; or download &lt;a target = &#34;&#34;_blank&#34;&#34; href = &#34;&#34;http://get.adobe.com/reader/&#34;&#34;&gt;Adobe PDF Reader&lt;/a&gt; to view the file.&#34; embed += &#34;&lt;/object&gt;&#34; ltEmbed.Text = String.Format(embed, ResolveUrl(&#34;~/Files/Test.pdf&#34;)) End If End Sub</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="https://i.imgur.com/AleEsPd.gif" alt="" width="362" height="479" /></p> <p>&nbsp;</p> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/184140/Display-PDF-inside-Ajax-Accordion-inside-ASPNet-Repeater-control-using-C-and-VBNet/https://www.aspforums.net:443/Threads/184140/Display-PDF-inside-Ajax-Accordion-inside-ASPNet-Repeater-control-using-C-and-VBNet/Wed, 03 Jul 2019 02:04:49 GMT