I have trawled the net over the last couple of days to find a way of solving my issue, quite a few have done it a different way to the way I've done it but I need to keep my project running the same
I'm using Visual Studio 2008, SQL Server 2008 with AJAX and C#
I've got a grid which is returning data as a cumulative total, it all works without an issue, have attached a collapsible panel extender and another grid to display sub elements, this is where I'm having difficulty as I cannot see the second gridview.
When it gets to the following I get an error "Object not set to an instance of an object"
((GridView)FindControl("GridView2)).DataSource = reader1;
Any assistance most appreciated, code below, have had to top and tail it due to content
What I have tried:
<asp:ScriptManager ID="ScriptManager1" runat="server">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="EmplID" CellPadding="4" ForeColor="#333333" GridLines="None" Width="700px" onrowcommand="GridView1_RowCommand"
onrowediting="GridView1_RowEditing">
<rowstyle backcolor="#EFF3FB">
<columns> <asp:BoundField DataField="EmpID" HeaderText="EmpID" InsertVisible="False" ReadOnly="True" SortExpression="EmpID" Visible="False" />
<asp:TemplateField HeaderText="Project/Order" SortExpression="linknumber" HeaderStyle-HorizontalAlign="Center">
<itemtemplate>
<asp:LinkButton ID="LinkButton1" runat="server" Text='<%# Bind("EmpID") %>'>
<cc1:CollapsiblePanelExtender ID="CollapsiblePanelExtender1" runat="server"
TargetControlID="Panel1" CollapsedSize="0"
Collapsed="true" ExpandControlID="LinkButton1" CollapseControlID="LinkButton1"
AutoCollapse="false" AutoExpand="false"
ScrollContents="true" ExpandDirection="Vertical">
<asp:Panel ID="Panel1" runat="server">
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="EmpID">
<columns> <asp:TemplateField HeaderText="EmpID">
<itemtemplate>
<asp:Label ID="lblAbID" runat="server" Text='<%# Bind("AbID") %>'>
<itemstyle width="50px" horizontalalign="Center">
<asp:TemplateField HeaderText="EmpID">
<itemtemplate>
<asp:Label ID="lblEmpIDD" runat="server" Text='<%# Bind("Date","{0:dd/MM/yyyy}") %>'>
<itemstyle width="50px" horizontalalign="Center">
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<asp:TemplateField HeaderText="EmpID">
<itemtemplate>
<asp:Label ID="lblEmpID" runat="server" Text='<%# Bind("EmpID") %>'>
<itemstyle width="50px" horizontalalign="Center">
<asp:TemplateField HeaderText="SerNo">
<itemtemplate>
<asp:Label ID="lblESerNoID" runat="server" Text='<%# Bind("SerNo") %>'>
<itemstyle width="100px" horizontalalign="Center">
C# Code
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
SQLQueryDD = "select e.EmployeeID, e.SerNo from tbl_Emp e where e.EmpID = 12";
FullStringDD = SQLQueryDD;
SqlCommand cmd = new SqlCommand(FullStringDD, connAMP);
connAMP.Open();
GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
reader1 = cmd.ExecuteReader();
((GridView)FindControl("GridView2")).DataSource = reader1;
((GridView)FindControl("GridView2")).DataBind();
connAMP.Close();
}
catch (Exception ex)
{
}
}