Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - Object reference not set to an instance of an object.

 
Thread Tools Search this Thread
Old 01-26-2005, 03:47 PM   #1
Default Object reference not set to an instance of an object.


Hello all, can someone please be my second pair of eyes! I'm getting the
above error at line: for(int i = 0; i <= dlstScope.Items.Count-1; i++).

My code's below: (dlstScope is a nested dlstScope in a repeater). Thanks all.

private void butSave_Click(object sender, System.EventArgs e)
{
DataList dlstScope = (DataList)myRepeater.FindControl("dlstScope");

for(int i = 0; i <= dlstScope.Items.Count-1; i++)
{
string Answer =
((DropDownList)dlstScope.Items[i].FindControl("txtAnswer")).SelectedValue;
string WorksheetQuestionID =
((Literal)dlstScope.Items[i].FindControl("lblWorksheetQuestionID")).Text;
string WorksheetID =
((Literal)dlstScope.Items[i].FindControl("lblWorksheetID")).Text;
Action(WorksheetQuestionID, Convert.ToInt32(WorksheetID),
Convert.ToInt32(Answer));
}
}





=?Utf-8?B?Sm9u?=
  Reply With Quote
Old 01-26-2005, 03:58 PM   #2
Karl Seguin
 
Posts: n/a
Default Re: Object reference not set to an instance of an object.

Jon,
Seems pretty straightforward with the information you've provided.
dlstScope is null, which means myRepeater.FindControl("dlstScope") didn't
return a value.

As you say, dlstScope is nested within the repeater, presumably the
ItemTemplate. If this is so, dlstScope isn't a child of myRepeater and thus
won't be found (as you are seeing). Instead, dlstScope is a child of an
Item of myRepeater..such as myRepeater.Items[0].FindControl("dlstScope")

What I can't tell you is which Item you want...you might want to loop
through all of them (in which case you'll have multiple dlstScope) or you
might want a particular one..but from the provided code I can't say which or
how to do it.

Hope this helps,
karl

--
MY ASP.Net tutorials
http://www.openmymind.net/


"Jon" <> wrote in message
news:C959676E-037C-446E-94B7-...
> Hello all, can someone please be my second pair of eyes! I'm getting the
> above error at line: for(int i = 0; i <= dlstScope.Items.Count-1; i++).
>
> My code's below: (dlstScope is a nested dlstScope in a repeater). Thanks

all.
>
> private void butSave_Click(object sender, System.EventArgs e)
> {
> DataList dlstScope = (DataList)myRepeater.FindControl("dlstScope");
>
> for(int i = 0; i <= dlstScope.Items.Count-1; i++)
> {
> string Answer =
> ((DropDownList)dlstScope.Items[i].FindControl("txtAnswer")).SelectedValue;
> string WorksheetQuestionID =
> ((Literal)dlstScope.Items[i].FindControl("lblWorksheetQuestionID")).Text;
> string WorksheetID =
> ((Literal)dlstScope.Items[i].FindControl("lblWorksheetID")).Text;
> Action(WorksheetQuestionID, Convert.ToInt32(WorksheetID),
> Convert.ToInt32(Answer));
> }
> }
>
>
>





Karl Seguin
  Reply With Quote
Old 01-26-2005, 03:59 PM   #3
Matt Berther
 
Posts: n/a
Default Re: Object reference not set to an instance of an object.
Hello Jon,

Clearly the problem is that dlstScope is null. Make sure that you've set
the id properly in the repeater template.

--
Matt Berther
http://www.mattberther.com

> Hello all, can someone please be my second pair of eyes! I'm getting
> the above error at line: for(int i = 0; i <= dlstScope.Items.Count-1;
> i++).
>
> My code's below: (dlstScope is a nested dlstScope in a repeater).
> Thanks all.
>
> private void butSave_Click(object sender, System.EventArgs e)
> {
> DataList dlstScope = (DataList)myRepeater.FindControl("dlstScope");
> for(int i = 0; i <= dlstScope.Items.Count-1; i++)
> {
> string Answer =
> ((DropDownList)dlstScope.Items[i].FindControl("txtAnswer")).SelectedVa
> lue;
> string WorksheetQuestionID =
> ((Literal)dlstScope.Items[i].FindControl("lblWorksheetQuestionID")).Te
> xt;
> string WorksheetID =
> ((Literal)dlstScope.Items[i].FindControl("lblWorksheetID")).Text;
> Action(WorksheetQuestionID, Convert.ToInt32(WorksheetID),
> Convert.ToInt32(Answer));
> }
> }





Matt Berther
  Reply With Quote
Old 01-26-2005, 04:03 PM   #4
obeOnline
 
Posts: n/a
Default Re: Object reference not set to an instance of an object.
Is there somewhere that you are using the "new" keyword on dlstScope?
You have to create a new instance of dlstScope at some point.



obeOnline
  Reply With Quote
Old 01-26-2005, 04:17 PM   #5
=?Utf-8?B?Sm9u?=
 
Posts: n/a
Default Re: Object reference not set to an instance of an object.
Karl, thats' great! You pointed me in the right direction. This is the code
that worked: Thanks again.

private void butSave_Click(object sender, System.EventArgs e)
{
for(int j = 0; j <= myRepeater.Items.Count-1; j++)
{
DataList dlstScope =
(DataList)myRepeater.Items[j].FindControl("dlstScope");

for(int i = 0; i <= dlstScope.Items.Count-1; i++)
{
string Answer =
((DropDownList)dlstScope.Items[i].FindControl("txtAnswer")).SelectedValue;
string WorksheetQuestionID =
((Literal)dlstScope.Items[i].FindControl("lblWorksheetQuestionID")).Text;
string WorksheetID =
((Literal)dlstScope.Items[i].FindControl("lblWorksheetID")).Text;
Action(WorksheetQuestionID, Convert.ToInt32(WorksheetID),
Convert.ToInt32(Answer));
}
}

"Karl Seguin" wrote:

>
> Jon,
> Seems pretty straightforward with the information you've provided.
> dlstScope is null, which means myRepeater.FindControl("dlstScope") didn't
> return a value.
>
> As you say, dlstScope is nested within the repeater, presumably the
> ItemTemplate. If this is so, dlstScope isn't a child of myRepeater and thus
> won't be found (as you are seeing). Instead, dlstScope is a child of an
> Item of myRepeater..such as myRepeater.Items[0].FindControl("dlstScope")
>
> What I can't tell you is which Item you want...you might want to loop
> through all of them (in which case you'll have multiple dlstScope) or you
> might want a particular one..but from the provided code I can't say which or
> how to do it.
>
> Hope this helps,
> karl
>
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/
>
>
> "Jon" <> wrote in message
> news:C959676E-037C-446E-94B7-...
> > Hello all, can someone please be my second pair of eyes! I'm getting the
> > above error at line: for(int i = 0; i <= dlstScope.Items.Count-1; i++).
> >
> > My code's below: (dlstScope is a nested dlstScope in a repeater). Thanks

> all.
> >
> > private void butSave_Click(object sender, System.EventArgs e)
> > {
> > DataList dlstScope = (DataList)myRepeater.FindControl("dlstScope");
> >
> > for(int i = 0; i <= dlstScope.Items.Count-1; i++)
> > {
> > string Answer =
> > ((DropDownList)dlstScope.Items[i].FindControl("txtAnswer")).SelectedValue;
> > string WorksheetQuestionID =
> > ((Literal)dlstScope.Items[i].FindControl("lblWorksheetQuestionID")).Text;
> > string WorksheetID =
> > ((Literal)dlstScope.Items[i].FindControl("lblWorksheetID")).Text;
> > Action(WorksheetQuestionID, Convert.ToInt32(WorksheetID),
> > Convert.ToInt32(Answer));
> > }
> > }
> >
> >
> >

>
>
>



=?Utf-8?B?Sm9u?=
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
COM object in asp.net fluoronator Software 1 03-04-2008 07:48 PM
Opinions on Reference DVD's? Jordan DVD Video 20 07-26-2007 02:04 AM
How do I reference a radio button in a datalist control aspnetNewbie General Help Related Topics 0 04-30-2007 05:49 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46