Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8491439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:25:29+00:00 2026-06-10T22:25:29+00:00

I am trying to make something like this: Master detail gridview But give me

  • 0

I am trying to make something like this:

Master detail gridview

But give me error in this line from cs file when i click Show details in the GridView:

gvRow.FindControl("GridView2").Visible = true;

I am trying when i click Show details to see the Names from other table where ID_Proba is = to ID from first Table.

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
    DataKeyNames="id" DataSourceID="SqlDataSource1" 
    onselectedindexchanged="GridView1_SelectedIndexChanged">
    <Columns>
        <asp:BoundField 
        DataField="id" 
        HeaderText="id" 
        ReadOnly="True" 
        SortExpression="id" InsertVisible="False" />
        <asp:BoundField 
        DataField="name" 
        HeaderText="name" 
        SortExpression="name" />
        <asp:CommandField ShowSelectButton="True" 
              SelectText="Show Details"/>
    </Columns>
    <EmptyDataTemplate>
        <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" 
            DataKeyNames="id" DataSourceID="SqlDataSource2" Visible="False">
            <Columns>
                <asp:BoundField DataField="id" 
                                HeaderText="id" 
                                SortExpression="id" InsertVisible="False" ReadOnly="True" />
                <asp:BoundField DataField="id_proba" 
                                HeaderText="id_proba" 
                                SortExpression="id_proba" />
                <asp:BoundField DataField="name" 
                                HeaderText="name" 
                                SortExpression="name" />
            </Columns>
        </asp:GridView>
    </EmptyDataTemplate>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:ProbaConnectionString %>" 
    SelectCommand="SELECT * FROM [Proba1]"></asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" 
    ConnectionString="<%$ ConnectionStrings:ProbaConnectionString %>" 
    SelectCommand="SELECT * FROM [proba3] WHERE ([id_proba] = @id_proba)">
    <SelectParameters>
        <asp:Parameter Name="id_proba" Type="Int32" />
    </SelectParameters>
</asp:SqlDataSource>
</form>

This is the cs file:

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
    foreach (GridViewRow gvRow in GridView1.Rows)
    {
        gvRow.FindControl("GridView2").Visible = true;
    }
    SqlDataSource2.SelectParameters[0].DefaultValue = GridView1.SelectedDataKey[0].ToString();
    GridView1.SelectedRow.FindControl("GridView2").Visible = true;    
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T22:25:31+00:00Added an answer on June 10, 2026 at 10:25 pm

    You need to take “GridView2” out of the EmptyDataTemplate and put it in a TemplateField. When you have data, the EmptyDataTemplate is not created at all, and also there is no grid in each row, because this template is for the whole grid.

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        DataKeyNames="id" DataSourceID="SqlDataSource1" 
        onselectedindexchanged="GridView1_SelectedIndexChanged">
        <Columns>
            <asp:BoundField 
            DataField="id" 
            HeaderText="id" 
            ReadOnly="True" 
            SortExpression="id" InsertVisible="False" />
            <asp:BoundField 
            DataField="name" 
            HeaderText="name" 
            SortExpression="name" />
            <asp:CommandField ShowSelectButton="True" 
                  SelectText="Show Details"/>
    <asp:TemplateField>
        <ItemTemplate>
            <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" 
                DataKeyNames="id" DataSourceID="SqlDataSource2" Visible="False">
                <Columns>
                    <asp:BoundField DataField="id" 
                                    HeaderText="id" 
                                    SortExpression="id" InsertVisible="False" ReadOnly="True" />
                    <asp:BoundField DataField="id_proba" 
                                    HeaderText="id_proba" 
                                    SortExpression="id_proba" />
                    <asp:BoundField DataField="name" 
                                    HeaderText="name" 
                                    SortExpression="name" />
                </Columns>
            </asp:GridView>
        </ItemTemplate>
    <asp:TemplateField>
    </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ProbaConnectionString %>" 
        SelectCommand="SELECT * FROM [Proba1]"></asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ProbaConnectionString %>" 
        SelectCommand="SELECT * FROM [proba3] WHERE ([id_proba] = @id_proba)">
        <SelectParameters>
            <asp:Parameter Name="id_proba" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>
    </form>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to make a simple program to catalogue books. Something like this, for example:
Trying to make a simple program to catalogue books. Something like this, for example:
I am trying to make terrain mesh, and for now got something like this:
I'm trying to make something like this: I have a mapactivity and when the
I'm currently in a .NET4 Windows Forms Application. I'm trying to make something like
I'm trying to make something pretty simple, but I simply suck at regular expressions.
I'm new to C++ and trying to make two simple functions, but something goes
Got question. If i make query to server i use something like this: mysql_query(select
I'm trying to set up a Master/Detail grid using the Grid control from Telerik's
I've a custom module with custom table, now, i'm trying to make something like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.