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.Nested user control to display relational record in page like nested GridView using C# and VB.Net in ASP.Net<p>i havent wrote code yet, just make a page and two user control that &nbsp;page has a button, when click on it show first user control with some info &nbsp;from user table with a button and want &nbsp;to click button in first user control &nbsp;show related info from detailed user table for every user in second user control</p> <p>I want to know, how transfe userId from user table in first user control that use in second user control and dataset</p>https://www.aspforums.net:443/Threads/105569/Nested-user-control-to-display-relational-record-in-page-like-nested-GridView-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/105569/Nested-user-control-to-display-relational-record-in-page-like-nested-GridView-using-C-and-VBNet-in-ASPNet/Fri, 14 Jul 2017 09:54:05 GMTNested user control to display relational record in page like nested GridView using C# and VB.Net in ASP.Net<p>Hi <a class="username" rel="jimcode"> jimcode</a>,</p> <p>I have created sample code which full-fill your requirement. So Please refer the below code.</p> <p><span style="text-decoration: underline;">HTML</span></p> <pre class="brush: html">&lt;div&gt; &lt;Uc:ucUsers ID=&#34;ucUsersData&#34; runat=&#34;server&#34; /&gt; &lt;/div&gt;</pre> <p>and you need to Register the user control on top of the aspx page.</p> <pre class="brush: html">&lt;%@ Register TagPrefix=&#34;Uc&#34; Src=&#34;~/Users.ascx&#34; TagName=&#34;ucUsers&#34; %&gt;</pre> <p><span style="text-decoration: underline;">Web User Control</span></p> <p><span style="text-decoration: underline;">Users.ascx</span></p> <pre class="brush: html">&lt;%@ Control Language=&#34;C#&#34; AutoEventWireup=&#34;true&#34; CodeFile=&#34;Users.ascx.cs&#34; Inherits=&#34;Users&#34; %&gt; &lt;%@ Register TagPrefix=&#34;childUc&#34; Src=&#34;~/UserDetails.ascx&#34; TagName=&#34;ucUserDetails&#34; %&gt; &lt;style type=&#34;text/css&#34;&gt; body { font-family: Arial; font-size: 10pt; } table { border: 1px solid #ccc; } table th { background-color: #F7F7F7; color: #333; font-weight: bold; } table th, table td { padding: 5px; border-color: #ccc; } &lt;/style&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js&#34;&gt;&lt;/script&gt; &lt;link rel=&#34;stylesheet&#34; href=&#34;http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css&#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;[id*=btnshow]&#34;).live(&#34;click&#34;, function () { if ($(this).attr(&#34;value&#34;) == &#34;Show&#34;) { $(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;value&#34;, &#34;Hide&#34;); $(this).attr(&#34;class&#34;, &#34;btn btn-primary&#34;); } else { $(this).attr(&#34;text&#34;, &#34;Show&#34;); $(this).closest(&#34;tr&#34;).next().remove(); $(this).attr(&#34;value&#34;, &#34;Show&#34;); $(this).attr(&#34;class&#34;, &#34;btn btn-success&#34;); } return false; }); &lt;/script&gt; &lt;asp:GridView ID=&#34;gvUsers&#34; runat=&#34;server&#34; AutoGenerateColumns=&#34;false&#34; CssClass=&#34;Grid&#34; DataKeyNames=&#34;CustomerID&#34; OnRowDataBound=&#34;OnRowDataBound&#34;&gt; &lt;Columns&gt; &lt;asp:TemplateField HeaderText=&#34;Action&#34;&gt; &lt;ItemTemplate&gt; &lt;asp:Button ID=&#34;btnshow&#34; Text=&#34;Show&#34; class=&#34;btn btn-success&#34; runat=&#34;server&#34; /&gt; &lt;asp:Panel ID=&#34;Panel1&#34; runat=&#34;server&#34; Style=&#34;display: none&#34;&gt; &lt;childUc:ucUserDetails ID=&#34;UserDetails&#34; runat=&#34;server&#34; /&gt; &lt;/asp:Panel&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:BoundField ItemStyle-Width=&#34;150px&#34; DataField=&#34;ContactName&#34; HeaderText=&#34;Contact Name&#34; /&gt; &lt;asp:BoundField ItemStyle-Width=&#34;150px&#34; DataField=&#34;City&#34; HeaderText=&#34;City&#34; /&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; </pre> <p><span style="text-decoration: underline;">C#</span></p> <pre class="brush: csharp">private string constring = ConfigurationManager.ConnectionStrings[&#34;constring&#34;].ConnectionString; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.PopulateUsers(); } } private void PopulateUsers() { SqlConnection con = new SqlConnection(constring); SqlCommand cmd = new SqlCommand(&#34;Select TOP 10 CustomerId,ContactName,City From Customers&#34;, con); SqlDataAdapter sda = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); sda.Fill(dt); gvUsers.DataSource = dt; gvUsers.DataBind(); } protected void OnRowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { string customerId = gvUsers.DataKeys[e.Row.RowIndex].Value.ToString(); ((e.Row.FindControl(&#34;UserDetails&#34;) as UserControl).FindControl(&#34;gvUserDetails&#34;) as GridView).DataSource = GetChildData(customerId); ((e.Row.FindControl(&#34;UserDetails&#34;) as UserControl).FindControl(&#34;gvUserDetails&#34;) as GridView).DataBind(); } } private DataTable GetChildData(string userId) { SqlConnection con = new SqlConnection(constring); SqlCommand cmd = new SqlCommand(&#34;Select * From Customers Where CustomerId=@CustomerId&#34;, con); cmd.Parameters.AddWithValue(&#34;@CustomerId&#34;, userId); SqlDataAdapter sda = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); sda.Fill(dt); return dt; }</pre> <p><span style="text-decoration: underline;">UserDetails.ascx</span></p> <pre class="brush: html">&lt;%@ Control Language=&#34;C#&#34; AutoEventWireup=&#34;true&#34; CodeFile=&#34;UserDetails.ascx.cs&#34; Inherits=&#34;UserDetails&#34; %&gt; &lt;asp:GridView ID=&#34;gvUserDetails&#34; runat=&#34;server&#34; AutoGenerateColumns=&#34;false&#34; CssClass=&#34;ChildGrid&#34;&gt; &lt;Columns&gt; &lt;asp:TemplateField&gt; &lt;ItemTemplate&gt; Address:&lt;asp:Label ID=&#34;lblAddress&#34; Text=&#39;&lt;%#Eval(&#34;Address&#34;)%&gt;&#39; runat=&#34;server&#34; /&gt; PostalCode:&lt;asp:Label ID=&#34;lblPostalCode&#34; Text=&#39;&lt;%#Eval(&#34;PostalCode&#34;)%&gt;&#39; runat=&#34;server&#34; /&gt; Phone:&lt;asp:Label ID=&#34;lblPhone&#34; Text=&#39;&lt;%#Eval(&#34;Phone&#34;)%&gt;&#39; runat=&#34;server&#34; /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; </pre> <p><span style="text-decoration: underline;">Vb.Net</span></p> <pre class="brush: vb">Private constring As String = ConfigurationManager.ConnectionStrings(&#34;constring&#34;).ConnectionString Protected Sub Page_Load(sender As Object, e As EventArgs) If Not IsPostBack Then Me.PopulateUsers() End If End Sub Private Sub PopulateUsers() Dim con As New SqlConnection(constring) Dim cmd As New SqlCommand(&#34;Select TOP 10 CustomerId,ContactName,City From Customers&#34;, con) Dim sda As New SqlDataAdapter(cmd) Dim dt As New DataTable() sda.Fill(dt) gvUsers.DataSource = dt gvUsers.DataBind() End Sub Protected Sub OnRowDataBound(sender As Object, e As GridViewRowEventArgs) If e.Row.RowType = DataControlRowType.DataRow Then Dim customerId As String = gvUsers.DataKeys(e.Row.RowIndex).Value.ToString() TryCast(TryCast(e.Row.FindControl(&#34;UserDetails&#34;), UserControl).FindControl(&#34;gvUserDetails&#34;), GridView).DataSource = GetChildData(customerId) TryCast(TryCast(e.Row.FindControl(&#34;UserDetails&#34;), UserControl).FindControl(&#34;gvUserDetails&#34;), GridView).DataBind() End If End Sub Private Function GetChildData(userId As String) As DataTable Dim con As New SqlConnection(constring) Dim cmd As New SqlCommand(&#34;Select * From Customers Where CustomerId=@CustomerId&#34;, con) cmd.Parameters.AddWithValue(&#34;@CustomerId&#34;, userId) Dim sda As New SqlDataAdapter(cmd) Dim dt As New DataTable() sda.Fill(dt) Return dt End Function</pre> <p><span style="text-decoration: underline;">Screenshot</span></p> <p><img src="http://i.imgur.com/GB8wZCT.gif" alt="" width="388" height="476" /></p> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/105569/Nested-user-control-to-display-relational-record-in-page-like-nested-GridView-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/105569/Nested-user-control-to-display-relational-record-in-page-like-nested-GridView-using-C-and-VBNet-in-ASPNet/Wed, 19 Jul 2017 07:34:46 GMTNested user control to display relational record in page like nested GridView using C# and VB.Net in ASP.Net<p><strong>I try it.</strong></p> <p><strong>Thanks so much.</strong></p>https://www.aspforums.net:443/Threads/105569/Nested-user-control-to-display-relational-record-in-page-like-nested-GridView-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/105569/Nested-user-control-to-display-relational-record-in-page-like-nested-GridView-using-C-and-VBNet-in-ASPNet/Wed, 19 Jul 2017 07:41:38 GMTNested user control to display relational record in page like nested GridView using C# and VB.Net in ASP.NetInstead of saying thanks mark the reply or replies(if multiple) that helped as Answer.https://www.aspforums.net:443/Threads/105569/Nested-user-control-to-display-relational-record-in-page-like-nested-GridView-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/105569/Nested-user-control-to-display-relational-record-in-page-like-nested-GridView-using-C-and-VBNet-in-ASPNet/Mon, 24 Jul 2017 08:37:28 GMT