![]() |
|
|
|||||||
![]() |
ASP Net - Object reference not set to an instance of an object. |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
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?= |
|
|
|
|
#2 |
|
Posts: n/a
|
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 |
|
|
|
#3 |
|
Posts: n/a
|
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 |
|
|
|
#4 |
|
Posts: n/a
|
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 |
|
|
|
#5 |
|
Posts: n/a
|
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?= |
|
![]() |
| Thread Tools | Search this Thread |
|
|
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 |