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 7181039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:28:26+00:00 2026-05-28T17:28:26+00:00

I am trying to nest one gridview within another, but I cannot get the

  • 0

I am trying to nest one gridview within another, but I cannot get the data to populate in the second grid view. I am getting an error when trying to set the data source of the second data grid (saying it is null). Can anyone help?
Here is the aspx page:

<div id="divSource" runat="server" align="center">
<asp:GridView ID="Source" runat="server" AutoGenerateColumns="False" DataKeyNames="sourceLineItem"  CSSClass="viewSourceGrid" OnRowDataBound="PopulateDateCodes">
    <Columns>
        <asp:TemplateField InsertVisible="False" HeaderStyle-Width="70px">
            <ItemTemplate>
                <asp:Label CssClass="sourceHeader" runat="server" Text= '<%# "Source: " + (Container.DataItemIndex + 1).ToString() %>'> </asp:Label>
            </ItemTemplate>
        </asp:TemplateField> 
        <asp:BoundField DataField="nfdBroker" HeaderText="NFD/Broker" InsertVisible="False" ReadOnly="True" SortExpression="nfdBroker" />
        <asp:BoundField DataField="locationDescription" HeaderText="Material Location" SortExpression="materialLocation" />
        <asp:BoundField DataField="origPkg" HeaderText="Original Packaging?" SortExpression="origPkg" />
        <asp:BoundField DataField="oemCC" HeaderText="OEM C of C? " InsertVisible="False" ReadOnly="True" SortExpression="oemCC" />
        <asp:BoundField DataField="minBuyQty" HeaderText="Minimum Buy Qty" SortExpression="minBuyQty" />
        <asp:BoundField DataField="deliveryInfo" HeaderText="Delivery" SortExpression="delUOM" />

        <asp:TemplateField InsertVisible="False" HeaderText="Date Codes" >
            <ItemTemplate>               
                <asp:GridView ID="DateCodeGrid" runat="server" InsertVisible="False" DataKeyNames="dateCode"  CSSClass="viewSourceGrid" >
                    <Columns>
                        <asp:BoundField DataField="dateCode" SortExpression="dateCode">
                            <ItemStyle Width="20%" />
                        </asp:BoundField>
                    </Columns>
                </asp:GridView>
            </ItemTemplate>
        </asp:TemplateField>

    </Columns>
</asp:GridView>

and then here is the code behind:

    public partial class Controls_ViewSource : System.Web.UI.UserControl
{
    //Set the Source Line Item
    public int SourceLineItem { get; set; }

    protected void Page_Load(object sender, EventArgs e)
    {
        this.SourceLineItem = SourceLineItem;
        RequestDB db = new RequestDB();
        DataSet sources = db.GetSource(int.Parse(Request.QueryString["requestNumber"]), SourceLineItem);
        Source.DataSource = sources;
        Source.DataBind();

    }

    protected void PopulateDateCodes(object sender, GridViewRowEventArgs e)
    {
        RequestDB db = new RequestDB();
        int index = e.Row.RowIndex;
        GridView gv = (GridView)Source.Rows[0].FindControl("DateCodeGrid");
        //int sourceLineItem = int.Parse(Source.DataKeyNames[0].ToString());
        //Response.Write(Source.DataKeyNames[0].ToString());
        DataSet dateCodes = db.GetDateCodes(71);
        gv.DataSource = dateCodes;
        gv.DataBind();

    }
}
  • 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-05-28T17:28:27+00:00Added an answer on May 28, 2026 at 5:28 pm

    You would need to find the nested grid view in the row that is being data bound:

    GridViewRow row = e.Row;
    

    You need to make sure you are only doing this for data rows, not header or footer rows:

    if(row.RowType == DataControlRowType.DataRow)
    {
      // Find the nested grid view
      GridView nested = (GridView)row.FindControl("DateCodeGrid");
    
      // The rest of your code for binding the nested grid view follows here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to nest a form within another using submit_to_remote but it does a
I am trying to nest a UITabBar inside another one, like so: UITabBarController *tabController
I'm trying to nest a foreach within an if/else using Razor, but am having
I am trying to nest one loop in another and break out of the
I've been trying to nest sets within sets but to no avail. This concept
I've spent hours trying to get my code to work, its a rats nest
I'm trying to multicore a function (in Windows), which, at one point, calls another
I'm trying to nest a frameset in an iframe and I can't get the
I am trying to nest in SQL statements that are trying to pull data
Trying to connect to a SQL Server 2005 instance remotely but getting the following

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.