在转发器中的复选框中进行验证 [英] validation in chekboxes in repeater
本文介绍了在转发器中的复选框中进行验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
'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
<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>
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)
我需要检查用户是否选择套餐,他是否也必须选择单人或双人房套餐
我希望我在问题中很清楚
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
推荐答案
如果您收到对象引用未设置为对象实例",则某些操作不会返回类实例,例如FindControl可能并没有真正找到您的控件.
您在问题中非常清楚,几乎是您的代码难以理解.
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.
这篇关于在转发器中的复选框中进行验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文