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 in Image Control on DataList ImageButton Click using C# and VB.Net in ASP.Net<p>Hi <a class="username" rel="rajeesh"> rajeesh</a>,</p> <p>Rfer below sample.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html">&lt;asp:DataList ID=&#34;DataList1&#34; runat=&#34;server&#34; HorizontalAlign=&#34;Left&#34; OnItemCommand=&#34;DataList1_ItemCommand&#34; RepeatColumns=&#34;5&#34; RepeatDirection=&#34;Horizontal&#34; Width=&#34;319px&#34;&gt; &lt;ItemTemplate&gt; &lt;table class=&#34;style1&#34;&gt; &lt;tr&gt; &lt;td&gt; &lt;asp:ImageButton ID=&#34;ImageButton1&#34; runat=&#34;server&#34; CommandName=&#34;itemclick&#34; Height=&#34;50px&#34; ImageUrl=&#39;&lt;%# Eval(&#34;image&#34;) %&gt;&#39; Width=&#34;50px&#34; /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &amp;nbsp; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;asp:HiddenField ID=&#34;HiddenField2&#34; runat=&#34;server&#34; Value=&#39;&lt;%# Eval(&#34;id&#34;) %&gt;&#39; /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/ItemTemplate&gt; &lt;/asp:DataList&gt; &lt;br /&gt; &lt;br /&gt; &lt;asp:Image ID=&#34;Image2&#34; runat=&#34;server&#34; Height=&#34;100px&#34; Width=&#34;100px&#34; /&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;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.Data</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) { DataTable dt = new DataTable(); dt.Columns.Add(&#34;id&#34;); dt.Columns.Add(&#34;image&#34;); dt.Rows.Add(&#34;1&#34;, &#34;http://static.flickr.com/66/199481236_dc98b5abb3_s.jpg&#34;); dt.Rows.Add(&#34;2&#34;, &#34;http://static.flickr.com/75/199481072_b4a0d09597_s.jpg&#34;); dt.Rows.Add(&#34;3&#34;, &#34;http://static.flickr.com/57/199481087_33ae73a8de_s.jpg&#34;); dt.Rows.Add(&#34;4&#34;, &#34;http://static.flickr.com/77/199481108_4359e6b971_s.jpg&#34;); dt.Rows.Add(&#34;5&#34;, &#34;http://static.flickr.com/58/199481143_3c148d9dd3_s.jpg&#34;); dt.Rows.Add(&#34;6&#34;, &#34;http://static.flickr.com/72/199481203_ad4cdcf109_s.jpg&#34;); dt.Rows.Add(&#34;7&#34;, &#34;http://static.flickr.com/58/199481218_264ce20da0_s.jpg&#34;); dt.Rows.Add(&#34;8&#34;, &#34;http://static.flickr.com/69/199481255_fdfe885f87_s.jpg&#34;); dt.Rows.Add(&#34;9&#34;, &#34;http://static.flickr.com/60/199480111_87d4cb3e38_s.jpg&#34;); dt.Rows.Add(&#34;10&#34;, &#34;http://static.flickr.com/70/229228324_08223b70fa_s.jpg&#34;); DataList1.DataSource = dt; DataList1.DataBind(); } } protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e) { if (e.CommandName == &#34;itemclick&#34;) { string url = (e.Item.FindControl(&#34;ImageButton1&#34;) as ImageButton).ImageUrl; Image2.ImageUrl = url; } }</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 dt As DataTable = New DataTable() dt.Columns.Add(&#34;id&#34;) dt.Columns.Add(&#34;image&#34;) dt.Rows.Add(&#34;1&#34;, &#34;http://static.flickr.com/66/199481236_dc98b5abb3_s.jpg&#34;) dt.Rows.Add(&#34;2&#34;, &#34;http://static.flickr.com/75/199481072_b4a0d09597_s.jpg&#34;) dt.Rows.Add(&#34;3&#34;, &#34;http://static.flickr.com/57/199481087_33ae73a8de_s.jpg&#34;) dt.Rows.Add(&#34;4&#34;, &#34;http://static.flickr.com/77/199481108_4359e6b971_s.jpg&#34;) dt.Rows.Add(&#34;5&#34;, &#34;http://static.flickr.com/58/199481143_3c148d9dd3_s.jpg&#34;) dt.Rows.Add(&#34;6&#34;, &#34;http://static.flickr.com/72/199481203_ad4cdcf109_s.jpg&#34;) dt.Rows.Add(&#34;7&#34;, &#34;http://static.flickr.com/58/199481218_264ce20da0_s.jpg&#34;) dt.Rows.Add(&#34;8&#34;, &#34;http://static.flickr.com/69/199481255_fdfe885f87_s.jpg&#34;) dt.Rows.Add(&#34;9&#34;, &#34;http://static.flickr.com/60/199480111_87d4cb3e38_s.jpg&#34;) dt.Rows.Add(&#34;10&#34;, &#34;http://static.flickr.com/70/229228324_08223b70fa_s.jpg&#34;) DataList1.DataSource = dt DataList1.DataBind() End If End Sub Protected Sub DataList1_ItemCommand(ByVal source As Object, ByVal e As DataListCommandEventArgs) If e.CommandName = &#34;itemclick&#34; Then Dim url As String = (TryCast(e.Item.FindControl(&#34;ImageButton1&#34;), ImageButton)).ImageUrl Image2.ImageUrl = url End If End Sub</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="https://i.imgur.com/zL5FSCE.gif" alt="" width="323" height="396" /></p>https://www.aspforums.net:443/Threads/173384/Display-Image-in-Image-Control-on-DataList-ImageButton-Click-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/173384/Display-Image-in-Image-Control-on-DataList-ImageButton-Click-using-C-and-VBNet-in-ASPNet/Thu, 05 Sep 2019 03:40:14 GMT