Ctype error in Load control

Discussion in 'ASP .Net' started by AlecL, Feb 1, 2007.

  1. AlecL

    AlecL Guest

    Hi,

    I am trying to load control as a record is being updated in a backend
    database. The codes reads like this:

    Dim ds As DataSet
    CType(Page.FindControl("ddlStatus"),
    DropDownList).SelectedValue = _status
    Dim sql As String = "select * from _loanApp where status=" &
    _status
    ds =
    SqlHelper.ExecuteDataset(ConfigurationSettings.AppSettings("DSN"), _
    CommandType.Text, sql)

    CType(Page.FindControl("dgList"), DataGrid).DataSource = ds
    CType(Page.FindControl("dgList"), DataGrid).DataBind()

    but it is giving me this error.

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

    The stack trace reads:

    [NullReferenceException: Object reference not set to an instance of an
    object.]

    Any help is appreciated.
     
    AlecL, Feb 1, 2007
    #1
    1. Advertising

  2. Debug it. Set a breakpoint and see what returns null.

    --
    Eliyahu Goldin,
    Software Developer & Consultant
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    "AlecL" <> wrote in message
    news:...
    > Hi,
    >
    > I am trying to load control as a record is being updated in a backend
    > database. The codes reads like this:
    >
    > Dim ds As DataSet
    > CType(Page.FindControl("ddlStatus"),
    > DropDownList).SelectedValue = _status
    > Dim sql As String = "select * from _loanApp where status=" &
    > _status
    > ds =
    > SqlHelper.ExecuteDataset(ConfigurationSettings.AppSettings("DSN"), _
    > CommandType.Text, sql)
    >
    > CType(Page.FindControl("dgList"), DataGrid).DataSource = ds
    > CType(Page.FindControl("dgList"), DataGrid).DataBind()
    >
    > but it is giving me this error.
    >
    > System.NullReferenceException: Object reference not set to an instance
    > of an object.
    >
    > The stack trace reads:
    >
    > [NullReferenceException: Object reference not set to an instance of an
    > object.]
    >
    > Any help is appreciated.
    >
     
    Eliyahu Goldin, Feb 1, 2007
    #2
    1. Advertising

  3. AlecL

    Aidy Guest

    What line gives the error? It will be one of the Page.FindControl commands
    not finding the control you're asking for.

    "AlecL" <> wrote in message
    news:...
    > Hi,
    >
    > I am trying to load control as a record is being updated in a backend
    > database. The codes reads like this:
    >
    > Dim ds As DataSet
    > CType(Page.FindControl("ddlStatus"),
    > DropDownList).SelectedValue = _status
    > Dim sql As String = "select * from _loanApp where status=" &
    > _status
    > ds =
    > SqlHelper.ExecuteDataset(ConfigurationSettings.AppSettings("DSN"), _
    > CommandType.Text, sql)
    >
    > CType(Page.FindControl("dgList"), DataGrid).DataSource = ds
    > CType(Page.FindControl("dgList"), DataGrid).DataBind()
    >
    > but it is giving me this error.
    >
    > System.NullReferenceException: Object reference not set to an instance
    > of an object.
    >
    > The stack trace reads:
    >
    > [NullReferenceException: Object reference not set to an instance of an
    > object.]
    >
    > Any help is appreciated.
    >
     
    Aidy, Feb 1, 2007
    #3
  4. AlecL

    AlecL Guest

    On Feb 1, 10:51 am, "Aidy" <> wrote:
    > What line gives the error? It will be one of the Page.FindControl commands
    > not finding the control you're asking for.
    >
    > "AlecL" <> wrote in message
    >
    > news:...
    >
    >
    >
    > > Hi,

    >
    > > I am trying to load control as a record is being updated in a backend
    > > database. The codes reads like this:

    >
    > > Dim ds As DataSet
    > > CType(Page.FindControl("ddlStatus"),
    > > DropDownList).SelectedValue = _status
    > > Dim sql As String = "select * from _loanApp where status=" &
    > > _status
    > > ds =
    > > SqlHelper.ExecuteDataset(ConfigurationSettings.AppSettings("DSN"), _
    > > CommandType.Text, sql)

    >
    > > CType(Page.FindControl("dgList"), DataGrid).DataSource = ds
    > > CType(Page.FindControl("dgList"), DataGrid).DataBind()

    >
    > > but it is giving me this error.

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

    >
    > > The stack trace reads:

    >
    > > [NullReferenceException: Object reference not set to an instance of an
    > > object.]

    >
    > > Any help is appreciated.- Hide quoted text -

    >
    > - Show quoted text -


    Yes it is the CType(Page.FindControl("ddlStatus"),
    DropDownList).SelectedValue = _status line .

    Thanks
     
    AlecL, Feb 1, 2007
    #4
  5. AlecL

    Aidy Guest

    ddlStatus won't be a dropdownlist with view state enabled then.

    Can;t really say much more given the relevant code.

    "AlecL" <> wrote in message
    news:...
    > On Feb 1, 10:51 am, "Aidy" <> wrote:
    >> What line gives the error? It will be one of the Page.FindControl
    >> commands
    >> not finding the control you're asking for.
    >>
    >> "AlecL" <> wrote in message
    >>
    >> news:...
    >>
    >>
    >>
    >> > Hi,

    >>
    >> > I am trying to load control as a record is being updated in a backend
    >> > database. The codes reads like this:

    >>
    >> > Dim ds As DataSet
    >> > CType(Page.FindControl("ddlStatus"),
    >> > DropDownList).SelectedValue = _status
    >> > Dim sql As String = "select * from _loanApp where status=" &
    >> > _status
    >> > ds =
    >> > SqlHelper.ExecuteDataset(ConfigurationSettings.AppSettings("DSN"), _
    >> > CommandType.Text, sql)

    >>
    >> > CType(Page.FindControl("dgList"), DataGrid).DataSource = ds
    >> > CType(Page.FindControl("dgList"), DataGrid).DataBind()

    >>
    >> > but it is giving me this error.

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

    >>
    >> > The stack trace reads:

    >>
    >> > [NullReferenceException: Object reference not set to an instance of an
    >> > object.]

    >>
    >> > Any help is appreciated.- Hide quoted text -

    >>
    >> - Show quoted text -

    >
    > Yes it is the CType(Page.FindControl("ddlStatus"),
    > DropDownList).SelectedValue = _status line .
    >
    > Thanks
    >
     
    Aidy, Feb 1, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark Kamoski
    Replies:
    3
    Views:
    15,856
    Jay B. Harlow [MVP - Outlook]
    Aug 9, 2003
  2. Stan Sainte-Rose

    Ctype and Web Custom Control question

    Stan Sainte-Rose, Sep 7, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    363
    Stan Sainte-Rose
    Sep 7, 2004
  3. Justin Dutoit

    Help- LoadControl and Ctype error

    Justin Dutoit, Feb 23, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    757
    Sonu Kapoor [MVP]
    Feb 23, 2006
  4. Replies:
    3
    Views:
    194
  5. Justin Dutoit

    LoadControl and CType error

    Justin Dutoit, Feb 23, 2006, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    130
    Justin Dutoit
    Feb 23, 2006
Loading...

Share This Page