Null error when  binding dataset to gridview

MoniMatthews
MoniMatthews used Ask the Experts™
on
When binding dataset to a GridView I am getting System.NullReferenceException was unhandled by user code   Message="Object reference not set to an instance of an object."

Report custom control file:
        //initialize the get data class
        dataGet dg = new dataGet();

        DataSet ds = null;
        public string _str;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                bindData();
            }
        }


       
        public void str(string dtChange)
        {
 
            TextBox objTextBox = new TextBox();
            objTextBox.Text = dtChange.ToString();
                if (objTextBox.Text.ToString() != "Enter a date" && objTextBox.Text.ToString() != "")
                {
                    string currentDate = objTextBox.Text.ToString();
                    ds = dg.getPrevoiusRptData(currentDate);
                   
                    GridView2.DataSource = ds;
                    GridView2.DataBind();
                }
                else
                {
                    string currentDate = DateTime.Now.ToString("dd/MM/yyyy");
                    ds = dg.getPrevoiusRptData(currentDate);
                    GridView2.DataSource = ds;
                    GridView2.DataBind();
                }
      }

 
      protected void bindData()
        {
 
            if (Page.Title == "rptPresent")
            {
            GridView1.Visible = true;
            ds = dg.getPresentRptData();
            GridView1.DataSource = ds;
            GridView1.DataBind();

            }
           else if (Page.Title == "rptPrevious")
            {
                GridView2.Visible = true;
                string currentDate = DateTime.Now.ToString("dd/MM/yyyy");
                ds = dg.getPrevoiusRptData(currentDate);
                GridView2.DataSource = ds;
                GridView2.DataBind();
            }

        }

DatePick custom control:
        //initialize the get user control  
        ucReports rpts = new ucReports();

       protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                txt.Text = "Enter a date";
            }

        }
        protected void imgCal(object sender, ImageClickEventArgs e)
        {
            Panel1.Visible = true;
        }

       
        protected void cal_DayRender(object sender, EventArgs e)
        {
            txt.Text = Calendar1.SelectedDate.ToString("dd/MM/yyyy");
            Panel1.Visible = false;
            rpts.str(txt.Text);
        }
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Can you send us a stack trace?
my guess would be that the dg.getPresentRptData(); or dg.getPresentRptData(currentDate); is returing null

Author

Commented:
no its not the dataset is not the cause of the null. the problem is when a user selects a date from the calendar custom control the gridview in the other control is returning null.
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

Author

Commented:
Stack Trace:
 Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 57:                //GridView gv = new GridView();
Line 58:                //GridView2 = gv;
Line 59:                GridView2.DataSource = ds;
Line 60:                GridView2.DataBind();
Line 61:            }


Source File: C:\Inetpub\wwwroot\eDeliverySystem\eDelivery\eDelivery\UserControls\ucReports.ascx.cs    Line: 59

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
   eDelivery.UserControls.ucReports.View2(Object sender, EventArgs e) in C:\Inetpub\wwwroot\eDeliverySystem\eDelivery\eDelivery\UserControls\ucReports.ascx.cs:59
   eDelivery.UserControls.ucDatePicker.cal_DayRender(Object sender, EventArgs e) in C:\Inetpub\wwwroot\eDeliverySystem\eDelivery\eDelivery\UserControls\ucDatePicker.ascx.cs:42
   System.Web.UI.WebControls.Calendar.OnSelectionChanged() +117
   System.Web.UI.WebControls.Calendar.SelectRange(DateTime dateFrom, DateTime dateTo) +242
   System.Web.UI.WebControls.Calendar.RaisePostBackEvent(String eventArgument) +827
   System.Web.UI.WebControls.Calendar.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +177
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746

Commented:
hey,
can you put a breakpoint in Binddata and tell us where it is failing.

Thanks and regards,
Venki

Author

Commented:
it is failing here GridView2.DataSource = ds;
When I step through the process, I get:
GridView2      null      System.Web.UI.WebControls.GridView

Commented:
can you put a breakpoint in bindData and check what is getting assigned to ds, as Mohal has pointed out I think the methods are returning null.
The error is in the .ucReports.View2() (line 59) method just like the stack trace says.  Somewhere before line 57 you should be initializing the variable 'ds' with the desired result set after selecting a date on a calendar.  But for some unknown reason the variable is being set to null.

Commented:
where is GridView2 setup

Author

Commented:
on ucReports
it uses the str method

Commented:
are you sure that this line
ds = dg.getPrevoiusRptData(currentDate);

is returning data.

Author

Commented:
yes, I have verified it several times.

Commented:
if possible can you post the code of gridview2

Commented:
oops submitted before completing the line

if possible can you post the code of gridview2 I mean the gridview2 setup piece

Author

Commented:
the gridview2 control is on the .ascx page or am I misunderstanding?

Commented:
hey,
Sorry if I am asking too many questions.

you said that
it is failing here GridView2.DataSource = ds;
When I step through the process, I get:
GridView2      null      System.Web.UI.WebControls.GridView

where is it. Is it in str method or BindData?

Thanks and regards,
Venki

Author

Commented:
sorry,
str
and please ask as many question as you want, you r helping me.

Commented:
In your datepick custom control, you are doing....

ucReports rpts = new ucReports();
Please note that this does not initialize the controls in the Report Custom Control.. hence your GridView2 is not yet initialized to a new GridView.. There will be a initialization function that you need to call.... like UserControl.InitializeAsUserControl(this)..

-Ajitha

Author

Commented:
I am sorry I don't totally understand where I would add this line of code. Will you explain this in a little more detail?

Commented:
Can you show the complete code of DatePick Custom control and Report Custom control

-Ajitha

Author

Commented:
ok,
which page should I add that line of code?
Commented:
Replace the following.....

 ucReports rpts = new ucReports();

to.....

UserControl uc = new UserControl();
ucReports rpts = (ucReports)uc.LoadControl(<<path of the ascx file of ucReports>>)...

You will probably have to move this lines of code to the DayRender method.

-Ajitha

Author

Commented:
ok,
last question when you say path of ascx file do you mean like eDelivery.UserControls.ucReports ?

Commented:
path of the physical file.. You have ucReports.ascx file right?
send us the source code in the ucReports.ascx.cs file. ( or at least the function View2())

Author

Commented:
That worked! Thank you.
Would you happen to know why data doesn't show up on the page?

Commented:
May be you are not adding that user control to the page.. you are dynamically creating it right. where are you binding it to the page/date user control?

~Ajitha

Author

Commented:
in the str method:
        public void str(string dtChange)
        {
 
            TextBox objTextBox = new TextBox();
            objTextBox.Text = dtChange.ToString();
                if (objTextBox.Text.ToString() != "Enter a date" && objTextBox.Text.ToString() != "")
                {
                    string currentDate = objTextBox.Text.ToString();
                    ds = dg.getPrevoiusRptData(currentDate);
                   
                    GridView2.DataSource = ds;
                    GridView2.DataBind();
                }
                else
                {
                    string currentDate = DateTime.Now.ToString("dd/MM/yyyy");
                    ds = dg.getPrevoiusRptData(currentDate);
                    GridView2.DataSource = ds;
                    GridView2.DataBind();
                }
      }

Commented:
not that one.. I am talking about ucReports. You are creating this control using LoadControl.. but that still needs to be added to the Controls collection of DatePick custom control... like this..

this.Controls.add(ucReportsCtl)...

~Ajitha

Author

Commented:
that is ucReports but here isucDatePicker that pass the date to ucReports that has the gidview2 control

        protected void cal_DayRender(object sender, EventArgs e)
        {
            UserControl uc = new UserControl();
            ucReports rpts = (ucReports)uc.LoadControl("~/UserControls/ucReports.ascx");

            txt.Text = Calendar1.SelectedDate.ToString("dd/MM/yyyy");
            Panel1.Visible = false;
            rpts.str(txt.Text);
        }

Commented:
Right. here where are you binding the "rpts" control to the page? That is the one that contains gridview2 control right. and since its not yet bound to the page.. it will  notbe visible..
try adding this line at the end..

this.controls.add(rpts);

~Ajitha

Author

Commented:
It get this error:
'eDelivery.UserControls.ucDatePicker' does not contain a definition for 'controls' and no extension method 'controls' accepting a first argument of type 'eDelivery.UserControls.ucDatePicker' could be found (are you missing a using directive or an assembly reference?)

Commented:
can you tell me where the rpts should occur and what is parent control should be?

~Ajitha

Author

Commented:
rpts is called when the user has selected a date in the ucDatePicker the cal_DayRender method in ucDatePicker calls the rpts.str method in ucReports to re-populate the gridview2.
send us the source code for the  ucReports.View2(Object sender, EventArgs e)  method?

Author

Commented:
you have it, it is the str I just renamed it View2 but I have since changed it back.

Commented:
it is not looking correct.. the way you are refreshing the Reports control from the date control.. given that Reports control is not inside date control..

can you attach the relevant control and aspx page files..?

~Ajitha
the method ds = dg.getPrevoiusRptData(currentDate); is returning null

Author

Commented:
ASPX:
<%@ Register TagPrefix="eDel" TagName="ucDt" Src="~/UserControls/ucDatePicker.ascx" %>
<%@ Register TagPrefix="eDel" TagName="ucRpt" Src="~/UserControls/ucReports.ascx" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"></asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">
    <table width="900px" cellpadding="0" cellspacing="0">
<tr>
<td align="right" style="height:70px; font-family:Arial; font-size:34pt; width:900px; background-color:#ffffff; ">
<label style="color:#0287b4; size:4;">Previous Case Reporting</label>
</td>
</tr>
<tr>
<td>
<eDel:ucXpt id="Export" runat="server" />
</td>
</tr>
<tr>
<td>
<eDel:ucDt id="Pckr" runat="server" />
</td>
</tr>
<tr>
<td>
<eDel:ucRpt id="Rpt" runat="server" />
</td>
</tr>
</table>
</asp:Content>

ucDatePicker.ascx:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ucDatePicker.ascx.cs" Inherits="eDelivery.UserControls.ucDatePicker" %>

<table  width="900px" cellpadding="0" cellspacing="0">
<tr>
<td align="right" style="height:20px; font-family:Arial; font-size:12pt; width:900px;">
<label style="color:#0287b4; size:2;">Click calendar for date:</label> &nbsp;
<asp:TextBox ID="txt" runat="server" />
<asp:ImageButton ID="img" runat="server" ImageUrl="~/Images/Calendar.png" OnClick="imgCal" />
</td>
</tr>
<tr>
<td align="right" style="height:3px; font-family:Arial; font-size:12pt; width:900px; background-color:#ffffff; ">
</td>
</tr>
<tr>
<td align="right" style="height:1px; font-family:Arial; font-size:12pt; width:900px;">
    <asp:Panel ID="Panel1" runat="server" Visible="false">
        <asp:Calendar ID="Calendar1" runat="server" BackColor="White" BorderColor="#999999" CellPadding="4" DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt" ForeColor="#D1D1D1" Height="180px"
            Width="200px" OnSelectionChanged="cal_DayRender" >
            <SelectedDayStyle BackColor="#666666" Font-Bold="True" ForeColor="White" />
            <SelectorStyle BackColor="#CCCCCC" />
            <WeekendDayStyle BackColor="#AABAD2" ForeColor="White" />
            <TodayDayStyle BackColor="#CCCCCC" ForeColor="Black" />
            <OtherMonthDayStyle ForeColor="#808080" />
            <NextPrevStyle VerticalAlign="Bottom" />
            <DayHeaderStyle BackColor="#B5D1FA" Font-Bold="True" Font-Size="7pt" ForeColor="Black" />
            <TitleStyle BackColor="#284775" BorderColor="Black" Font-Bold="True" ForeColor="White"  />
        </asp:Calendar>
    </asp:Panel>
</td>
</tr>
</table>

ucReports.ascx:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ucReports.ascx.cs" Inherits="eDelivery.UserControls.ucReports" %>

    <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" BorderStyle="Solid" BorderWidth="2px" GridLines="Horizontal" Width="900px" AutoGenerateColumns="True" ShowFooter="false" AllowPaging="true" PageSize="15" OnPageIndexChanging="PageIndexChanging" Visible="false" >
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333"/>
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
        <HeaderStyle BackColor="#284775" Font-Bold="True" ForeColor="White" />
        <EditRowStyle BackColor="#999999" />
        <AlternatingRowStyle BackColor="#D8D8D8" ForeColor="#284775"  />    
    </asp:GridView>
   
<asp:GridView ID="GridView2" runat="server" CellPadding="4" ForeColor="#333333" BorderStyle="Solid" BorderWidth="2px" GridLines="Horizontal" Width="900px" AutoGenerateColumns="false" ShowFooter="true" AllowPaging="true" PageSize="15" OnPageIndexChanging="PageIndexChanging" Visible="false" EmptyDataText="No records available for today's date.">
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333"/>
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
        <HeaderStyle BackColor="#284775" Font-Bold="True" ForeColor="White" />
        <EditRowStyle BackColor="#999999" />
        <AlternatingRowStyle BackColor="#D8D8D8" ForeColor="#284775"  />      
<Columns>
                <asp:TemplateField HeaderText="Agency">
                 <ItemTemplate>
                     <asp:Label ID="Label1" runat="server" Text='<%# Bind("RECV_GRP_CD") %>'></asp:Label>
                 </ItemTemplate>
                 <EditItemTemplate>
                     <asp:Label ID="LabelEdt1" runat="server" Text='<%# Bind("RECV_GRP_CD") %>'></asp:Label>
                 </EditItemTemplate>
            </asp:TemplateField>

<asp:BoundField HeaderText="Distributed Cases" DataField="Num_Cases_distributed" />
</Columns>
    </asp:GridView>

Author

Commented:
the method ds = dg.getPrevoiusRptData(currentDate); is returning null
No it is not returning null.
the dataset returns the data based on the sql query.

Author

Commented:
the issue is with the controls on the ucReports.ascx page. the controls are not showing showing the data that has been passed to the controls on the page.
I have step this code, I see were the controls get populated but it is not showing the new data on the ucReports.ascx page.

Commented:
You have two user controls on the page. In the event handler of one user control (date picker), you want to refresh the second user control...but the date picker cannot access the page directly.. So I suggest you do this..

        protected void cal_DayRender(object sender, EventArgs e)
        {
            txt.Text = Calendar1.SelectedDate.ToString("dd/MM/yyyy");
            Panel1.Visible = false;
            rpts = (eDelivery.UserControls.ucReports)Page.FindControl("Rpt");
            rpts.str(txt.Text);
        }

remove the below lines...

            UserControl uc = new UserControl();
            ucReports rpts = (ucReports)uc.LoadControl("~/UserControls/ucReports.ascx");

~Ajitha

Author

Commented:
ajitha75:

Using this.Controls.Add(rpts); I can now get the date picked to show up in a label control but I am getting null reference at GridView2.DataBind();
I can't figure out why data in the dataset is not binding to my gridview.
Any ideas?

Commented:
Did you try the change I gave in comment '26438258'?

~Ajitha

Author

Commented:
i tried but i got errors when trying to run.

Commented:
Please note this is the correct way. Since you already have the control embedded on the page you need to create a new instance of the control through New keyword or LoadControl..

Can you let me know what errors you are getting?

~Ajitha

Author

Commented:
ok then should
rpts = (eDelivery.UserControls.ucReports)Page.FindControl("Rpt");

but "Rpt" doesn't exist, so should this be the ucreports or the Reports.aspx page?

Commented:
But Rpt does exist as per the below definition.... so basically what we are trying is get the usercontrol (UCReports0 from the page...

Rpt is the id of the control to find.

<eDel:ucRpt id="Rpt" runat="server" />

~Ajitha

Author

Commented:
I get this error:
 Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 42:             Panel1.Visible = false;
Line 43:             rpts = (eDelivery.UserControls.ucReports)Page.FindControl("Rpt");
Line 44:             rpts.str(txt.Text);
Line 45:             //rpts.str(txt.Text);
Line 46:             //rpts.strName = txt.Text;


Source File: C:\Inetpub\wwwroot\eDeliverySystem\eDelivery\eDelivery\UserControls\ucDatePicker.ascx.cs    Line: 44

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
   eDelivery.UserControls.ucDatePicker.cal_DayRender(Object sender, EventArgs e) in C:\Inetpub\wwwroot\eDeliverySystem\eDelivery\eDelivery\UserControls\ucDatePicker.ascx.cs:44
   System.Web.UI.WebControls.Calendar.OnSelectionChanged() +117
   System.Web.UI.WebControls.Calendar.SelectRange(DateTime dateFrom, DateTime dateTo) +242
   System.Web.UI.WebControls.Calendar.RaisePostBackEvent(String eventArgument) +827
   System.Web.UI.WebControls.Calendar.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +177
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746
try this.FindControl("Rpt") on line 43

Author

Commented:
I tried I got this error:
System.NullReferenceException was unhandled by user code
  Message="Object reference not set to an instance of an object."
  Source="eDelivery"
  StackTrace:
       at eDelivery.UserControls.ucDatePicker.cal_DayRender(Object sender, EventArgs e) in C:\Inetpub\wwwroot\eDeliverySystem\eDelivery\eDelivery\UserControls\ucDatePicker.ascx.cs:line 44
       at System.Web.UI.WebControls.Calendar.OnSelectionChanged()
       at System.Web.UI.WebControls.Calendar.SelectRange(DateTime dateFrom, DateTime dateTo)
       at System.Web.UI.WebControls.Calendar.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.WebControls.Calendar.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException:

Commented:
I have attached a cut down version of your code and the functionality that works. Please refer and see whats missing in your code...

~Ajitha
ucDatePicker.ascx
--------------------------------------------------------------------------
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ucDatePicker.ascx.cs" Inherits="eDelivery.UserControls.ucDatePicker" %>

<table  width="900px" cellpadding="0" cellspacing="0">
<tr>
<td align="right" style="height:20px; font-family:Arial; font-size:12pt; width:900px;">
<label style="color:#0287b4; size:2;">Click calendar for date:</label> &nbsp;
<asp:TextBox ID="txt" runat="server" />
<asp:ImageButton ID="img" runat="server" ImageUrl="~/Images/Calendar.png" OnClick="imgCal" />
</td>
</tr>
<tr>
<td align="right" style="height:3px; font-family:Arial; font-size:12pt; width:900px; background-color:#ffffff; ">
</td>
</tr>
<tr>
<td align="right" style="height:1px; font-family:Arial; font-size:12pt; width:900px;">
    <asp:Panel ID="Panel1" runat="server" Visible="false">
        <asp:Calendar ID="Calendar1" runat="server" BackColor="White" BorderColor="#999999" CellPadding="4" DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt" ForeColor="#D1D1D1" Height="180px" 
            Width="200px" OnSelectionChanged="cal_DayRender" >
            <SelectedDayStyle BackColor="#666666" Font-Bold="True" ForeColor="White" />
            <SelectorStyle BackColor="#CCCCCC" />
            <WeekendDayStyle BackColor="#AABAD2" ForeColor="White" />
            <TodayDayStyle BackColor="#CCCCCC" ForeColor="Black" />
            <OtherMonthDayStyle ForeColor="#808080" />
            <NextPrevStyle VerticalAlign="Bottom" />
            <DayHeaderStyle BackColor="#B5D1FA" Font-Bold="True" Font-Size="7pt" ForeColor="Black" />
            <TitleStyle BackColor="#284775" BorderColor="Black" Font-Bold="True" ForeColor="White"  />
        </asp:Calendar>
    </asp:Panel>
</td>
</tr>
</table>

ucDatePicker.ascx.cs
--------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace eDelivery.UserControls
{
	public partial class ucDatePicker : System.Web.UI.UserControl
	{
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                txt.Text = "Enter a date";
            }

        }
        protected void imgCal(object sender, ImageClickEventArgs e)
        {
            Panel1.Visible = true;
        }


        protected void cal_DayRender(object sender, EventArgs e)
        {
            txt.Text = Calendar1.SelectedDate.ToString("dd/MM/yyyy");
            Panel1.Visible = false;
            ucReports rpts = (ucReports)this.Page.FindControl("Rpt");
            rpts.str();
        }
	}
}
ucReports.ascx
--------------------------------------------------------------------------
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ucReports.ascx.cs" Inherits="eDelivery.UserControls.ucReports" %>

    <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" BorderStyle="Solid" BorderWidth="2px" GridLines="Horizontal" Width="900px" ShowFooter="false" >
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333"/>
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
        <HeaderStyle BackColor="#284775" Font-Bold="True" ForeColor="White" />
        <EditRowStyle BackColor="#999999" />
        <AlternatingRowStyle BackColor="#D8D8D8" ForeColor="#284775"  />    
    </asp:GridView>
    
ucReports.ascx.cs
--------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace eDelivery.UserControls
{
    public partial class ucReports : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public void str()
        {
            Response.Write("Got it here!");

        }
    }
}
ucTest.aspx
--------------------------------------------------------------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UCtest.aspx.cs" Inherits="WebApplication1.UCtest" %>
<%@ Register TagPrefix="eDel" TagName="ucDt" Src="ucDatePicker.ascx" %>
<%@ Register TagPrefix="eDel" TagName="ucRpt" Src="ucReports.ascx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
<table width="900px" cellpadding="0" cellspacing="0">
<tr>
<td align="right" style="height:70px; font-family:Arial; font-size:34pt; width:900px; background-color:#ffffff; ">
<label style="color:#0287b4; size:4;">Previous Case Reporting</label>
</td>
</tr>
<tr>
<td>

</td>
</tr>
<tr>
<td>
<eDel:ucDt id="Pckr" runat="server" />
</td>
</tr>
<tr>
<td>
<eDel:ucRpt id="Rpt" runat="server" />
</td>
</tr>
</table>
    </form>
</body>
</html>

Open in new window

Author

Commented:
this does not work for me
            ucReports rpts = (ucReports)this.Page.FindControl("Rpt");
            rpts.str();
without ucReports rpts = new ucReports();that is one difference and I send the date string, I have always been able to send the date string.

My issue has always been that the gridview control was giving null errors and not binding from the dataset.
Now I am not getting null from the gridview but  it is still not binding from the dataset.
If I send the data from the dataset to say a label control i get data.

Author

Commented:
It answer given resolved the null issue for me.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial