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.Find RadioButton inside nested Repeater on Parent Repeater Button Click using C# and VB.Net in ASP.Net<p>Hi <a class="username" rel="rani"> rani</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;html xmlns=&#34;http://www.w3.org/1999/xhtml&#34;&gt; &lt;head id=&#34;Head1&#34; 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; } .Grid, .ChildGrid { border: 1px solid #ccc; } .Grid td, .Grid th { border: 1px solid #ccc; } .Grid th { background-color: #B8DBFD; color: #333; font-weight: bold; } .ChildGrid td, .ChildGrid th { border: 1px solid #ccc; } .ChildGrid th { background-color: #ccc; color: #333; font-weight: bold; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;form id=&#34;form1&#34; runat=&#34;server&#34;&gt; &lt;asp:Repeater ID=&#34;rptCustomers&#34; runat=&#34;server&#34; OnItemDataBound=&#34;OnItemDataBound&#34;&gt; &lt;HeaderTemplate&gt; &lt;table class=&#34;Grid&#34; cellspacing=&#34;0&#34; rules=&#34;all&#34; border=&#34;1&#34;&gt; &lt;tr&gt; &lt;th scope=&#34;col&#34;&gt;&amp;nbsp;&lt;/th&gt; &lt;th scope=&#34;col&#34; style=&#34;width: 150px&#34;&gt;Name&lt;/th&gt; &lt;th scope=&#34;col&#34; style=&#34;width: 150px&#34;&gt;Country&lt;/th&gt; &lt;th scope=&#34;col&#34; style=&#34;width: 150px&#34;&gt;Action&lt;/th&gt; &lt;/tr&gt; &lt;/HeaderTemplate&gt; &lt;ItemTemplate&gt; &lt;tr&gt; &lt;td&gt; &lt;img alt=&#34;&#34; style=&#34;cursor: pointer&#34; src=&#34;images/plus.png&#34; /&gt; &lt;asp:Panel ID=&#34;pnlOrders&#34; runat=&#34;server&#34; Style=&#34;display: none&#34;&gt; &lt;asp:Repeater ID=&#34;rptOrders&#34; runat=&#34;server&#34;&gt; &lt;HeaderTemplate&gt; &lt;table class=&#34;ChildGrid&#34; cellspacing=&#34;0&#34; rules=&#34;all&#34; border=&#34;1&#34;&gt; &lt;tr&gt; &lt;th scope=&#34;col&#34; style=&#34;width: 150px&#34;&gt;Order Id&lt;/th&gt; &lt;th scope=&#34;col&#34; style=&#34;width: 150px&#34;&gt;&lt;/th&gt; &lt;/tr&gt; &lt;/HeaderTemplate&gt; &lt;ItemTemplate&gt; &lt;tr&gt; &lt;td&gt;&lt;asp:Label ID=&#34;lblOrderId&#34; runat=&#34;server&#34; Text=&#39;&lt;%# Eval(&#34;OrderId&#34;) %&gt;&#39; /&gt;&lt;/td&gt; &lt;td&gt; &lt;asp:RadioButton ID=&#34;rbYes&#34; Text=&#34;Yes&#34; runat=&#34;server&#34; GroupName=&#34;A&#34; /&gt; &lt;asp:RadioButton ID=&#34;rbNo&#34; Text=&#34;No&#34; runat=&#34;server&#34; GroupName=&#34;A&#34; /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/ItemTemplate&gt; &lt;FooterTemplate&gt; &lt;/table&gt; &lt;/FooterTemplate&gt; &lt;/asp:Repeater&gt; &lt;/asp:Panel&gt; &lt;asp:HiddenField ID=&#34;hfCustomerId&#34; runat=&#34;server&#34; Value=&#39;&lt;%# Eval(&#34;Id&#34;) %&gt;&#39; /&gt; &lt;/td&gt; &lt;td&gt;&lt;asp:Label ID=&#34;lblContactName&#34; runat=&#34;server&#34; Text=&#39;&lt;%# Eval(&#34;Name&#34;) %&gt;&#39; /&gt;&lt;/td&gt; &lt;td&gt;&lt;asp:Label ID=&#34;lblCity&#34; runat=&#34;server&#34; Text=&#39;&lt;%# Eval(&#34;Country&#34;) %&gt;&#39; /&gt;&lt;/td&gt; &lt;td&gt;&lt;asp:Button ID=&#34;btnGet&#34; Text=&#34;Get Values&#34; runat=&#34;server&#34; OnClick=&#34;GetSelected&#34; /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/ItemTemplate&gt; &lt;FooterTemplate&gt; &lt;/table&gt; &lt;/FooterTemplate&gt; &lt;/asp:Repeater&gt; &lt;br /&gt; &lt;asp:Label ID=&#34;lblMessage&#34; runat=&#34;server&#34; /&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34;&gt; $(&#34;body&#34;).on(&#34;click&#34;, &#34;[src*=plus]&#34;, function () { $(this).closest(&#34;tr&#34;).after(&#34;&lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;td colspan = &#39;999&#39;&gt;&#34; + $(this).next().html() + &#34;&lt;/td&gt;&lt;/tr&gt;&#34;) $(this).attr(&#34;src&#34;, &#34;images/minus.png&#34;); }); $(&#34;body&#34;).on(&#34;click&#34;, &#34;[src*=minus]&#34;, function () { $(this).attr(&#34;src&#34;, &#34;images/plus.png&#34;); $(this).closest(&#34;tr&#34;).next().remove(); }); &lt;/script&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt;</pre> <p><strong><span style="text-decoration: underline;">Namespaces</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> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { rptCustomers.DataSource = GetCustomers(); rptCustomers.DataBind(); } } private static DataTable GetCustomers() { DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[] { new DataColumn(&#34;Id&#34;, typeof(int)), new DataColumn(&#34;Name&#34;, typeof(string)), new DataColumn(&#34;Country&#34;,typeof(string)) }); dt.Rows.Add(1, &#34;John Hammond&#34;, &#34;United States&#34;); dt.Rows.Add(2, &#34;Mudassar Khan&#34;, &#34;India&#34;); dt.Rows.Add(3, &#34;Suzanne Mathews&#34;, &#34;France&#34;); dt.Rows.Add(4, &#34;Robert Schidner&#34;, &#34;Russia&#34;); return dt; } private static DataTable GetOrders() { DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[] { new DataColumn(&#34;OrderId&#34;, typeof(int)), new DataColumn(&#34;CustomerId&#34;, typeof(int)) }); dt.Rows.Add(1001, 1); dt.Rows.Add(1005, 1); dt.Rows.Add(1002, 2); dt.Rows.Add(1003, 3); dt.Rows.Add(1004, 4); return dt; } protected void OnItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { string customerId = (e.Item.FindControl(&#34;hfCustomerId&#34;) as HiddenField).Value; Repeater rptOrders = e.Item.FindControl(&#34;rptOrders&#34;) as Repeater; rptOrders.DataSource = GetOrders().Select(&#34;CustomerId=&#34; + customerId).CopyToDataTable(); rptOrders.DataBind(); } } protected void GetSelected(object sender, EventArgs e) { lblMessage.Text = &#34;&#34;; Button btn = sender as Button; foreach (RepeaterItem item in (btn.FindControl(&#34;rptOrders&#34;) as Repeater).Items) { if (item.ItemType == ListItemType.AlternatingItem || item.ItemType == ListItemType.Item) { Label orderId = (Label)item.FindControl(&#34;lblOrderId&#34;); RadioButton rbYes = (RadioButton)item.FindControl(&#34;rbYes&#34;); RadioButton rbNo = (RadioButton)item.FindControl(&#34;rbNo&#34;); string selected = rbYes.Checked ? rbYes.Text : rbNo.Text; lblMessage.Text += &#34;Order &#34; + orderId.Text + &#34; is &#34; + selected + &#34;&lt;br/&gt;&#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 rptCustomers.DataSource = GetCustomers() rptCustomers.DataBind() End If End Sub Private Shared Function GetCustomers() As DataTable Dim dt As DataTable = New DataTable() dt.Columns.AddRange(New DataColumn() {New DataColumn(&#34;Id&#34;, GetType(Integer)), New DataColumn(&#34;Name&#34;, GetType(String)), New DataColumn(&#34;Country&#34;, GetType(String))}) dt.Rows.Add(1, &#34;John Hammond&#34;, &#34;United States&#34;) dt.Rows.Add(2, &#34;Mudassar Khan&#34;, &#34;India&#34;) dt.Rows.Add(3, &#34;Suzanne Mathews&#34;, &#34;France&#34;) dt.Rows.Add(4, &#34;Robert Schidner&#34;, &#34;Russia&#34;) Return dt End Function Private Shared Function GetOrders() As DataTable Dim dt As DataTable = New DataTable() dt.Columns.AddRange(New DataColumn() { New DataColumn(&#34;OrderId&#34;, GetType(Integer)), New DataColumn(&#34;CustomerId&#34;, GetType(Integer))}) dt.Rows.Add(1001, 1) dt.Rows.Add(1005, 1) dt.Rows.Add(1002, 2) dt.Rows.Add(1003, 3) dt.Rows.Add(1004, 4) Return dt End Function Protected Sub OnItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs) If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then Dim customerId As String = (TryCast(e.Item.FindControl(&#34;hfCustomerId&#34;), HiddenField)).Value Dim rptOrders As Repeater = TryCast(e.Item.FindControl(&#34;rptOrders&#34;), Repeater) rptOrders.DataSource = GetOrders().[Select](&#34;CustomerId=&#34; &amp; customerId).CopyToDataTable() rptOrders.DataBind() End If End Sub Protected Sub GetSelected(ByVal sender As Object, ByVal e As EventArgs) lblMessage.Text = &#34;&#34; Dim btn As Button = TryCast(sender, Button) For Each item As RepeaterItem In (TryCast(btn.FindControl(&#34;rptOrders&#34;), Repeater)).Items If item.ItemType = ListItemType.AlternatingItem OrElse item.ItemType = ListItemType.Item Then Dim orderId As Label = CType(item.FindControl(&#34;lblOrderId&#34;), Label) Dim rbYes As RadioButton = CType(item.FindControl(&#34;rbYes&#34;), RadioButton) Dim rbNo As RadioButton = CType(item.FindControl(&#34;rbNo&#34;), RadioButton) Dim selected As String = If(rbYes.Checked, rbYes.Text, rbNo.Text) lblMessage.Text += &#34;Order &#34; &amp; orderId.Text &amp; &#34; is &#34; &amp; selected &amp; &#34;&lt;br/&gt;&#34; End If Next End Sub</pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><img src="https://i.imgur.com/CIvZs6G.jpg" alt="" width="406" height="278" /></p>https://www.aspforums.net:443/Threads/536992/Find-RadioButton-inside-nested-Repeater-on-Parent-Repeater-Button-Click-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/536992/Find-RadioButton-inside-nested-Repeater-on-Parent-Repeater-Button-Click-using-C-and-VBNet-in-ASPNet/Thu, 22 Aug 2019 06:57:03 GMT