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 Image from database based on ID using C# and VB.Net in ASP.Net<p>Hi <a class="username" rel="Faizal"> Faizal</a>,</p> <p>Refer below article and add where condition to the select query.</p> <h1 class="header"><a title="Upload and Display Images using Path stored in database in GridView in ASP.Net using C# and VB.Net'a" href="https://www.aspsnippets.com/Articles/Upload-and-Display-Images-using-Path-stored-in-database-in-GridView-in-ASPNet-using-C-and-VBNet.aspx">Upload and Display Images using Path stored in database in GridView in ASP.Net using C# and VB.Net</a></h1>https://www.aspforums.net:443/Threads/113658/Display-Image-from-database-based-on-ID-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/113658/Display-Image-from-database-based-on-ID-using-C-and-VBNet-in-ASPNet/Fri, 30 Aug 2019 06:50:26 GMTDisplay Image from database based on ID using C# and VB.Net in ASP.Net<p>Hi <a class="username" rel="Faizal"> Faizal</a>,</p> <p>Check this example. Now please take its reference and correct your code.</p> <p><strong><span style="text-decoration: underline;">HTML</span></strong></p> <pre class="brush: html">&lt;asp:TextBox runat=&#34;server&#34; ID=&#34;txtId&#34; /&gt; &lt;asp:Button Text=&#34;Search&#34; ID=&#34;btnSearch&#34; OnClick=&#34;Search&#34; runat=&#34;server&#34; /&gt; &lt;br /&gt; &lt;asp:Image ID=&#34;imgPhoto&#34; ImageUrl=&#34;&#34; runat=&#34;server&#34; Visible=&#34;false&#34; /&gt;</pre> <p><strong><span style="text-decoration: underline;">Code</span></strong></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void Search(object sender, EventArgs e) { imgPhoto.Visible = true; System.Data.DataRow[] dr = GetData().Select(&#34;Id=&#34; + txtId.Text.Trim()); if (dr.Length &gt; 0) { imgPhoto.ImageUrl = dr[0][&#34;Path&#34;].ToString(); imgPhoto.AlternateText = dr[0][&#34;Name&#34;].ToString(); } else { imgPhoto.ImageUrl = &#34;Images/NoImage.jpg&#34;; imgPhoto.AlternateText = &#34;Image not available.&#34;; } } private System.Data.DataTable GetData() { System.Data.DataTable dt = new System.Data.DataTable(); dt.Columns.AddRange(new System.Data.DataColumn[3] { new System.Data.DataColumn(&#34;Id&#34;, typeof(int)), new System.Data.DataColumn(&#34;Name&#34;, typeof(string)), new System.Data.DataColumn(&#34;Path&#34;,typeof(string)) }); dt.Rows.Add(1, &#34;Chrysanthemum&#34;, &#34;Images/Chrysanthemum.jpg&#34;); dt.Rows.Add(2, &#34;Desert&#34;, &#34;Images/Desert.jpg&#34;); dt.Rows.Add(3, &#34;Hydrangeas&#34;, &#34;Images/Hydrangeas.jpg&#34;); dt.Rows.Add(4, &#34;Jellyfish&#34;, &#34;Images/Jellyfish.jpg&#34;); return dt; }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub Search(ByVal sender As Object, ByVal e As EventArgs) imgPhoto.Visible = True Dim dr As System.Data.DataRow() = GetData().Select(&#34;Id=&#34; &amp; txtId.Text.Trim()) If dr.Length &gt; 0 Then imgPhoto.ImageUrl = dr(0)(&#34;Path&#34;).ToString() imgPhoto.AlternateText = dr(0)(&#34;Name&#34;).ToString() Else imgPhoto.ImageUrl = &#34;Images/NoImage.jpg&#34; imgPhoto.AlternateText = &#34;Image not available.&#34; End If End Sub Private Function GetData() As System.Data.DataTable Dim dt As System.Data.DataTable = New System.Data.DataTable() dt.Columns.AddRange(New System.Data.DataColumn(2) { New System.Data.DataColumn(&#34;Id&#34;, GetType(Integer)), New System.Data.DataColumn(&#34;Name&#34;, GetType(String)), New System.Data.DataColumn(&#34;Path&#34;, GetType(String))}) dt.Rows.Add(1, &#34;Chrysanthemum&#34;, &#34;Images/Chrysanthemum.jpg&#34;) dt.Rows.Add(2, &#34;Desert&#34;, &#34;Images/Desert.jpg&#34;) dt.Rows.Add(3, &#34;Hydrangeas&#34;, &#34;Images/Hydrangeas.jpg&#34;) dt.Rows.Add(4, &#34;Jellyfish&#34;, &#34;Images/Jellyfish.jpg&#34;) Return dt End Function</pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><img src="https://i.imgur.com/K111fpZ.gif" alt="" /></p>https://www.aspforums.net:443/Threads/113658/Display-Image-from-database-based-on-ID-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/113658/Display-Image-from-database-based-on-ID-using-C-and-VBNet-in-ASPNet/Fri, 30 Aug 2019 08:11:37 GMT