Help with Repeater Control +Checkboxes

ryodoan

Well-known member
Joined
Jul 16, 2004
Messages
65
Location
Ohio
Programming Experience
3-5
I have a repeater control that creates a list like this:



I want it so they can check the boxes, click a submit button, and it will take that info, and slap it into a database.

The code to check which boxes they checked is this:

VB.NET:
[size=2][color=#0000ff]
With[/color][/size][size=2] Repeater1
[/size][size=2][color=#0000ff]For[/color][/size][size=2][color=#0000ff]Each[/color][/size][size=2] _item [/size][size=2][color=#0000ff]As[/color][/size][size=2] RepeaterItem [/size][size=2][color=#0000ff]In[/color][/size][size=2] .Items
[/size][size=2][color=#0000ff]With[/color][/size][size=2] _item
[/size][size=2][color=#0000ff]Select[/color][/size][size=2][color=#0000ff]Case[/color][/size][size=2] .ItemType
[/size][size=2][color=#0000ff]Case[/color][/size][size=2] ListItemType.AlternatingItem, ListItemType.Item
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] _orgID [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]String[/color][/size][size=2] = [/size][size=2][color=#0000ff]DirectCast[/color][/size][size=2](.FindControl("lblOrgID"), Label).Text[/size]
[size=2][color=#008000]
[/color][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] _Freshman [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Boolean[/color][/size][size=2] = [/size][size=2][color=#0000ff]DirectCast[/color][/size][size=2](FindControl("chkFreshman"), CheckBox).Checked
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] _Sophomore [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Boolean[/color][/size][size=2] = [/size][size=2][color=#0000ff]DirectCast[/color][/size][size=2](FindControl("chkSophomore"), CheckBox).Checked
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] _Junior [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Boolean[/color][/size][size=2] = [/size][size=2][color=#0000ff]DirectCast[/color][/size][size=2](FindControl("chkJunior"), CheckBox).Checked
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] _Senior [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Boolean[/color][/size][size=2] = [/size][size=2][color=#0000ff]DirectCast[/color][/size][size=2](FindControl("chkSenior"), CheckBox).Checked
insertResult(Login.QuestionID, [/size][size=2][color=#0000ff]CType[/color][/size][size=2](_orgID, Int32), _Freshman, _Sophomore, _Junior, _Senior)
[/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]Select 
[/color][/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]With
[/color][/size][size=2][color=#0000ff]Next
[/color][/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]With
[/color][/size]

when it gets to line #72 (Dim _Freshman AsBoolean = DirectCast(FindControl("chkFreshman"), CheckBox).Checked) it says that "Object reference not set to an instance of an object. "

I tried changing the DirectCast to a Ctype, but it had the same error. It has no problem grabbing the data off of the label, but it cant seem to tell if the checkbox is checked or not... Any help would be greatly appreciated.

well.... I was checking over my post when I noticed something.... I had forgotten 4 fricken periods... 4 FRICKEN PERIODS.... so.... instead of .FindControl, I was just doing FindControl. So if anyone else has this problem, there is the answer.
 
Last edited:
Top Bottom