Click here to Skip to main content
15,893,644 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
'get how many packages have been selected         
Dim c As Int32
         Dim str As String
         For Each dataItem As RepeaterItem In Repeater1.Items             
Dim ckchecked As CheckBox = DirectCast(dataItem.FindControl("chk_packages"), CheckBox)             If ckchecked.Checked Then
                 
Dim chk_single As CheckBox = DirectCast(dataItem.FindControl("single_rate"), CheckBox)                 Dim chk_double As CheckBox = DirectCast(dataItem.FindControl("double_rate"), CheckBox)                 If chk_single.Checked Then
                     c = c + 1
                 ElseIf chk_double.Checked Then
                     c = c + 1
                 End If
             End If
         Next
         If c = 0 Then
             lbl_error_package.Visible = True
             lbl_error_package.Text = "please select at least one package"
         Else
             lbl_error_package.Visible = False
         End If

XML
<asp:Repeater ID="Repeater1"  runat="server">
             <HeaderTemplate>
<table border="1" width="100%">
<tr>
<th>id</th>
<th align=left>Room Categories</th>
<th>single</th>
<th>Double</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td width="5%">
    <asp:Label ID="Label3" runat="server" Text= '<%# Container.DataItem("packageid")%>' /></td>
<td> <asp:CheckBox ID="chk_packages" AutoPostBack=true runat="server" Text = <%#Container.DataItem("package_name")%> />  </td>
<td><%#Container.DataItem("single_rate")%><asp:CheckBox  AutoPostBack=true ID="single" Enabled=false runat="server" />Number of Rooms<asp:TextBox ID="txt_single" Enabled=false  width="10px"   MaxLength="2" runat="server"></asp:TextBox></td>
<td><%#Container.DataItem("double_rate")%><asp:CheckBox  AutoPostBack=true ID="Double" Enabled=false runat="server" />Number of Rooms<asp:TextBox ID="txt_double" Enabled =false  width="10px"   MaxLength="2" runat="server"></asp:TextBox></td>
<td></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
         </asp:Repeater>


MSIL
its unable to find control and give exception
Object reference not set to an instance of an object.


Dim chk_single As CheckBox = DirectCast(dataItem.FindControl("single_rate"), CheckBox)


i need to check if user select package he must select either single or double room package too

i hope i'm quite clear in problem
Posted
Updated 3-Dec-10 22:00pm
v2

1 solution

If you got "Object reference not set to an instance of an object", something didn't return a class instance, like FindControl probably didn't really find your control.

Your quite clear in the problem, it's your code that is nearly incomprehensible.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900