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.Hide Show ASP.Net DataList based on CheckBox Checked (Selected) using C# and VB.Net<p>Hi <a class="username" rel="nid@patel"> nid@patel</a>,</p> <p>Refer below sample.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html">&lt;script type=&#34;text/javascript&#34; src=&#34;https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34;&gt; $(function () { $(&#39;input[type=checkbox]&#39;).click(function () { var id = $(this)[0].id.toString().replace(&#39;CheckBox&#39;, &#39;&#39;); if ($(this).is(&#34;:checked&#34;)) { $(&#39;#DataList&#39; + id).hide(); } else { $(&#39;#DataList&#39; + id).show(); } }); }); &lt;/script&gt; &lt;div&gt; &lt;div&gt; &lt;div class=&#34;dropdown&#34;&gt; &lt;div class=&#34;dropdown-content&#34;&gt; &lt;a href=&#34;#&#34;&gt; &lt;asp:CheckBox ID=&#34;CheckBox1&#34; runat=&#34;server&#34; /&gt;Nozzle&lt;/a&gt; &lt;a href=&#34;#&#34;&gt; &lt;asp:CheckBox ID=&#34;CheckBox2&#34; runat=&#34;server&#34; /&gt;Lateral&lt;/a&gt; &lt;a href=&#34;#&#34;&gt; &lt;asp:CheckBox ID=&#34;CheckBox3&#34; runat=&#34;server&#34; /&gt;Submain Pipe&lt;/a&gt; &lt;a href=&#34;#&#34;&gt; &lt;asp:CheckBox ID=&#34;CheckBox4&#34; runat=&#34;server&#34; /&gt;Main Pipe&lt;/a&gt; &lt;a href=&#34;#&#34;&gt; &lt;asp:CheckBox ID=&#34;CheckBox5&#34; runat=&#34;server&#34; /&gt;Motor Pump&lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;hr /&gt; &lt;asp:DataList ID=&#34;DataList1&#34; runat=&#34;server&#34; BorderStyle=&#34;Double&#34;&gt; &lt;ItemTemplate&gt; nozzle_lph: &lt;asp:Label ID=&#34;nozzle_lphLabel&#34; runat=&#34;server&#34; Text=&#39;&lt;%# Eval(&#34;nozzle_lph&#34;) %&gt;&#39;&gt;&lt;/asp:Label&gt; &lt;br /&gt; &lt;br /&gt; &lt;/ItemTemplate&gt; &lt;/asp:DataList&gt; &lt;br /&gt; &lt;asp:DataList ID=&#34;DataList2&#34; runat=&#34;server&#34; BorderStyle=&#34;Double&#34;&gt; &lt;ItemTemplate&gt; lateral_mm: &lt;asp:Label ID=&#34;lateral_mmLabel&#34; runat=&#34;server&#34; Text=&#39;&lt;%# Eval(&#34;lateral_mm&#34;) %&gt;&#39;&gt;&lt;/asp:Label&gt; &lt;br /&gt; &lt;br /&gt; &lt;/ItemTemplate&gt; &lt;/asp:DataList&gt; &lt;br /&gt; &lt;asp:DataList ID=&#34;DataList3&#34; runat=&#34;server&#34; BorderStyle=&#34;Double&#34;&gt; &lt;ItemTemplate&gt; main_mm: &lt;asp:Label ID=&#34;main_mmLabel&#34; runat=&#34;server&#34; Text=&#39;&lt;%# Eval(&#34;main_mm&#34;) %&gt;&#39;&gt;&lt;/asp:Label&gt; &lt;br /&gt; &lt;br /&gt; &lt;/ItemTemplate&gt; &lt;/asp:DataList&gt; &lt;br /&gt; &lt;asp:DataList ID=&#34;DataList4&#34; runat=&#34;server&#34; BorderStyle=&#34;Double&#34;&gt; &lt;ItemTemplate&gt; submain_mm: &lt;asp:Label ID=&#34;submain_mmLabel&#34; runat=&#34;server&#34; Text=&#39;&lt;%# Eval(&#34;submain_mm&#34;) %&gt;&#39;&gt;&lt;/asp:Label&gt; &lt;br /&gt; &lt;br /&gt; &lt;/ItemTemplate&gt; &lt;/asp:DataList&gt; &lt;br /&gt; &lt;asp:DataList ID=&#34;DataList5&#34; runat=&#34;server&#34; BorderStyle=&#34;Double&#34;&gt; &lt;ItemTemplate&gt; Sp_mpump_hp: &lt;asp:Label ID=&#34;Sp_mpump_hpLabel&#34; runat=&#34;server&#34; Text=&#39;&lt;%# Eval(&#34;Sp_mpump_hp&#34;) %&gt;&#39;&gt;&lt;/asp:Label&gt; &lt;br /&gt; &lt;br /&gt; &lt;/ItemTemplate&gt; &lt;/asp:DataList&gt; &lt;/div&gt; &lt;/div&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 dt1 = new DataTable(); dt1.Columns.Add(&#34;nozzle_lph&#34;); dt1.Rows.Add(1); dt1.Rows.Add(1); DataTable dt2 = new DataTable(); dt2.Columns.Add(&#34;lateral_mm&#34;); dt2.Rows.Add(2); dt2.Rows.Add(2); DataTable dt3 = new DataTable(); dt3.Columns.Add(&#34;main_mm&#34;); dt3.Rows.Add(3); dt3.Rows.Add(3); DataTable dt4 = new DataTable(); dt4.Columns.Add(&#34;submain_mm&#34;); dt4.Rows.Add(4); dt4.Rows.Add(4); DataTable dt5 = new DataTable(); dt5.Columns.Add(&#34;Sp_mpump_hp&#34;); dt5.Rows.Add(5); dt5.Rows.Add(5); DataList1.DataSource = dt1; DataList1.DataBind(); DataList2.DataSource = dt2; DataList2.DataBind(); DataList3.DataSource = dt3; DataList3.DataBind(); DataList4.DataSource = dt4; DataList4.DataBind(); DataList5.DataSource = dt5; DataList5.DataBind(); } }</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 dt1 As DataTable = New DataTable() dt1.Columns.Add(&#34;nozzle_lph&#34;) dt1.Rows.Add(1) dt1.Rows.Add(1) Dim dt2 As DataTable = New DataTable() dt2.Columns.Add(&#34;lateral_mm&#34;) dt2.Rows.Add(2) dt2.Rows.Add(2) Dim dt3 As DataTable = New DataTable() dt3.Columns.Add(&#34;main_mm&#34;) dt3.Rows.Add(3) dt3.Rows.Add(3) Dim dt4 As DataTable = New DataTable() dt4.Columns.Add(&#34;submain_mm&#34;) dt4.Rows.Add(4) dt4.Rows.Add(4) Dim dt5 As DataTable = New DataTable() dt5.Columns.Add(&#34;Sp_mpump_hp&#34;) dt5.Rows.Add(5) dt5.Rows.Add(5) DataList1.DataSource = dt1 DataList1.DataBind() DataList2.DataSource = dt2 DataList2.DataBind() DataList3.DataSource = dt3 DataList3.DataBind() DataList4.DataSource = dt4 DataList4.DataBind() DataList5.DataSource = dt5 DataList5.DataBind() End If End Sub</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="https://i.imgur.com/WOLqcVG.gif" alt="" width="247" height="508" /></p>https://www.aspforums.net:443/Threads/882851/Hide-Show-ASPNet-DataList-based-on-CheckBox-Checked-Selected-using-C-and-VBNet/https://www.aspforums.net:443/Threads/882851/Hide-Show-ASPNet-DataList-based-on-CheckBox-Checked-Selected-using-C-and-VBNet/Wed, 21 Aug 2019 04:45:07 GMT