PC Review


Reply
Thread Tools Rate Thread

Ctype error in Load control

 
 
AlecL
Guest
Posts: n/a
 
      1st Feb 2007
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.

 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      1st Feb 2007
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
>



 
Reply With Quote
 
Aidy
Guest
Posts: n/a
 
      1st Feb 2007
What line gives the error? It will be one of the Page.FindControl commands
not finding the control you're asking for.

"AlecL" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
>



 
Reply With Quote
 
AlecL
Guest
Posts: n/a
 
      1st Feb 2007
On Feb 1, 10:51 am, "Aidy" <a...@noemail.xxxa.com> wrote:
> What line gives the error? It will be one of the Page.FindControl commands
> not finding the control you're asking for.
>
> "AlecL" <salmaan...@hotmail.com> wrote in message
>
> news:(E-Mail Removed)...
>
>
>
> > 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

 
Reply With Quote
 
Aidy
Guest
Posts: n/a
 
      1st Feb 2007
ddlStatus won't be a dropdownlist with view state enabled then.

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

"AlecL" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Feb 1, 10:51 am, "Aidy" <a...@noemail.xxxa.com> wrote:
>> What line gives the error? It will be one of the Page.FindControl
>> commands
>> not finding the control you're asking for.
>>
>> "AlecL" <salmaan...@hotmail.com> wrote in message
>>
>> news:(E-Mail Removed)...
>>
>>
>>
>> > 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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DNS - Failed to load control error on booting/logging in. Kontaminator Windows Vista General Discussion 3 7th May 2007 04:23 PM
cType error? Dave Microsoft Dot NET Framework Forms 1 20th Nov 2006 05:50 AM
Help- LoadControl and Ctype error Justin Dutoit Microsoft ASP .NET 1 23rd Feb 2006 02:58 PM
Error: Failed to load viewstate. The control tree into =?Utf-8?B?Sm9zZW1h?= Microsoft C# .NET 0 9th May 2005 11:56 AM
Ctype and Web Custom Control question Stan Sainte-Rose Microsoft ASP .NET 0 7th Sep 2004 10:49 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:56 AM.