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 selected DataList Item in another page on Botton Click using C# and VB.Net in ASP.Net<p>Hi <a class="username" rel="Sadia.net"> Sadia.net</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> <p><strong>Default</strong></p> <pre class="brush: html">&lt;asp:DataList ID=&#34;dlemp&#34; runat=&#34;server&#34; Font-Names=&#34;Verdana&#34; Font-Size=&#34;X-Small&#34; RepeatDirection=&#34;Horizontal&#34; RepeatColumns=&#34;6&#34; Width=&#34;99%&#34; class=&#34;dlTable&#34; HorizontalAlign=&#34;Center&#34; Height=&#34;100%&#34; BorderColor=&#34;Black&#34; ShowFooter=&#34;False&#34; ShowHeader=&#34;False&#34;&gt; &lt;ItemTemplate&gt; &lt;div id=&#34;pricePlans&#34;&gt; &lt;ul id=&#34;plans&#34; style=&#34;border-bottom: 0px&#34;&gt; &lt;li class=&#34;plan&#34;&gt; &lt;ul class=&#34;planContainer&#34; style=&#34;border-bottom: 0px&#34;&gt; &lt;li class=&#34;title&#34;&gt; &lt;h2&gt; &lt;asp:Label ID=&#34;ProductName&#34; runat=&#34;server&#34; Font-Size=&#34;X-small&#34; Text=&#39;&lt;%# Eval(&#34;ProductName&#34;) %&gt;&#39;&gt;&lt;/asp:Label&gt; &lt;br /&gt; &lt;/li&gt; &lt;li class=&#34;title&#34;&gt; &lt;asp:Image ID=&#34;imgEmp&#34; runat=&#34;server&#34; Width=&#34;50%&#34; Height=&#34;50%&#34; ImageUrl=&#34;~/Chrysanthemum.jpg&#34; /&gt; &lt;/li&gt; &lt;li&gt; &lt;ul class=&#34;options&#34;&gt; &lt;li class=&#34;title&#34;&gt; &lt;h2&gt; &lt;asp:Label ID=&#34;Price&#34; runat=&#34;server&#34; Font-Size=&#34;X-small&#34; CssClass=&#34;center&#34; Text=&#39;&lt;%# Eval(&#34;Price&#34;) %&gt;&#39;&gt;&lt;/asp:Label&gt; &lt;br /&gt; &lt;/li&gt; &lt;div style=&#34;margin-left: 8%&#34;&gt; &lt;li&gt;&lt;b&gt;Code: &lt;/b&gt; &lt;asp:Label ID=&#34;CustomerID&#34; runat=&#34;server&#34; Text=&#39; &lt;%# Eval(&#34;Product_id&#34;) %&gt;&#39;&gt;&lt;/asp:Label&gt; &lt;li style=&#34;width: 100%; font-size: x-small;&#34;&gt;&lt;a href=&#34;ViewDetails.aspx?Id=&lt;%#Eval(&#34;Product_id&#34;) %&gt;&#34;&gt; Details&lt;/a&gt; &lt;/li&gt; &lt;asp:RadioButton ID=&#34;RadioButton1&#34; Text=&#34;Select&#34; runat=&#34;server&#34; /&gt; &lt;/li&gt; &lt;/div&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/ItemTemplate&gt; &lt;FooterTemplate&gt; &lt;/FooterTemplate&gt; &lt;/asp:DataList&gt;</pre> <p><strong>ViewDetails</strong></p> <pre class="brush: html">&lt;div&gt; Name: &lt;asp:Label ID=&#34;lblName&#34; runat=&#34;server&#34; /&gt;&lt;br /&gt; Price: &lt;asp:Label ID=&#34;lblPrice&#34; runat=&#34;server&#34; /&gt; &lt;/div&gt;</pre> <p><strong><span style="text-decoration: underline;">Namespace</span></strong></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><strong><span style="text-decoration: underline;">Code</span></strong></p> <p><strong>C#</strong></p> <p><span style="text-decoration: underline;">Default</span></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { // Populate DataTable from Database. System.Data.DataTable dt = new System.Data.DataTable(); dt.Columns.AddRange(new System.Data.DataColumn[] { new System.Data.DataColumn(&#34;Product_id&#34;, typeof(int)), new System.Data.DataColumn(&#34;ProductName&#34;, typeof(string)), new System.Data.DataColumn(&#34;Price&#34;,typeof(decimal)) }); dt.Rows.Add(1, &#34;Product 1&#34;, 1000); dt.Rows.Add(2, &#34;Product 2&#34;, 1100); dt.Rows.Add(3, &#34;Product 3&#34;, 1580); dt.Rows.Add(4, &#34;Product 4&#34;, 1256); dlemp.DataSource = dt; dlemp.DataBind(); } }</pre> <p><span style="text-decoration: underline;">ViewDetails</span></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { // Get Product_id from Query String. if (!string.IsNullOrEmpty(Request.QueryString[&#34;Id&#34;])) { DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[] { new DataColumn(&#34;Product_id&#34;, typeof(int)), new DataColumn(&#34;ProductName&#34;, typeof(string)), new DataColumn(&#34;Price&#34;,typeof(decimal)) }); dt.Rows.Add(1, &#34;Product 1&#34;, 1000); dt.Rows.Add(2, &#34;Product 2&#34;, 1100); dt.Rows.Add(3, &#34;Product 3&#34;, 1580); dt.Rows.Add(4, &#34;Product 4&#34;, 1256); // Filter record based on Product_id. DataTable product = dt.Select(&#34;Product_id=&#34; + Request.QueryString[&#34;Id&#34;]).CopyToDataTable(); lblName.Text = product.Rows[0][&#34;ProductName&#34;].ToString(); lblPrice.Text = product.Rows[0][&#34;Price&#34;].ToString(); } }</pre> <p><strong>VB.Net </strong></p> <p><span style="text-decoration: underline;">Default</span></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 &#39; Populate DataTable from Database. Dim dt As System.Data.DataTable = New System.Data.DataTable() dt.Columns.AddRange(New System.Data.DataColumn() { New System.Data.DataColumn(&#34;Product_id&#34;, GetType(Integer)), New System.Data.DataColumn(&#34;ProductName&#34;, GetType(String)), New System.Data.DataColumn(&#34;Price&#34;, GetType(Decimal))}) dt.Rows.Add(1, &#34;Product 1&#34;, 1000) dt.Rows.Add(2, &#34;Product 2&#34;, 1100) dt.Rows.Add(3, &#34;Product 3&#34;, 1580) dt.Rows.Add(4, &#34;Product 4&#34;, 1256) dlemp.DataSource = dt dlemp.DataBind() End If End Sub</pre> <p><span style="text-decoration: underline;">ViewDetails</span></p> <pre class="brush: vb">Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load &#39; Get Product_id from Query String. If Not String.IsNullOrEmpty(Request.QueryString(&#34;Id&#34;)) Then Dim dt As DataTable = New DataTable() dt.Columns.AddRange(New DataColumn() { New DataColumn(&#34;Product_id&#34;, GetType(Integer)), New DataColumn(&#34;ProductName&#34;, GetType(String)), New DataColumn(&#34;Price&#34;, GetType(Decimal))}) dt.Rows.Add(1, &#34;Product 1&#34;, 1000) dt.Rows.Add(2, &#34;Product 2&#34;, 1100) dt.Rows.Add(3, &#34;Product 3&#34;, 1580) dt.Rows.Add(4, &#34;Product 4&#34;, 1256) &#39; Filter record based on Product_id. Dim product As DataTable = dt.Select(&#34;Product_id=&#34; &amp; Request.QueryString(&#34;Id&#34;)).CopyToDataTable() lblName.Text = product.Rows(0)(&#34;ProductName&#34;).ToString() lblPrice.Text = product.Rows(0)(&#34;Price&#34;).ToString() End If End Sub</pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><img src="https://i.imgur.com/0AewuPH.gif" alt="" width="395" height="296" /></p>https://www.aspforums.net:443/Threads/572136/Display-selected-DataList-Item-in-another-page-on-Botton-Click-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/572136/Display-selected-DataList-Item-in-another-page-on-Botton-Click-using-C-and-VBNet-in-ASPNet/Tue, 27 Aug 2019 03:17:01 GMT