Finding Control of GridView from User Control Class
<p>I have a following GridView defined in my user control page named GridControl.ascx.</p>

<pre><code>&lt;asp:GridView ID="GridProd" runat="server" RowStyle-CssClass="GridProdGrid" 
    BackColor="White" BorderColor="#DEDFDE" BorderStyle="None"
    BorderWidth="1px" CellPadding="10" ForeColor="Black" GridLines="Vertical" 
    AutoGenerateEditButton="True" OnRowEditing="GridProd_RowEditing" 
    AllowSorting="True" OnSorting="Set_Sort" DataKeyNames="ProductID" 
    AutoGenerateColumns="False" AutoGenerateSelectButton="True" 
    OnSelectedIndexChanging="GridProd_SelectedIndexChanging"&gt;
</code></pre>

<p>I am using this control on ProductList.aspx.
Basically I want to display only the selected items on my another page named ItemList.aspx. I am trying to use the following code but it is throwing me null reference exception.</p>

<pre><code>GridView gd = (GridView)this.Page.PreviousPage.FindControl("GridProd");

/*For each row in GridView gd obtained from previous page*/
foreach (GridViewRow rows in gd.Rows)
{
    /*We will get the checkbox to check if it's checked or not*/
    CheckBox cb = (CheckBox)rows.FindControl("checktoadd");

    if (cb.Checked)
    {
        string prodname = rows.Cells[2].Text;
        string prodprice = rows.Cells[4].Text;
        string categoryname = rows.Cells[5].Text;
        dt.Rows.Add(prodname,prodprice,categoryname);
    }

    /*Binding the datatable to the new gridview*/
    gridorderlist.DataSource = dt;
    gridorderlist.DataBind();
}
</code></pre>

<p>When I was not using usercontrol, I had this gridview defined in ProductList.aspx page and it was working fine. I am confused how to access gridview defined in usercontrol page.</p>